The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TransparencyController.cs 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Transparency.Models;
  7. using Teknik.Areas.Transparency.ViewModels;
  8. using Teknik.Controllers;
  9. using Teknik.Models;
  10. namespace Teknik.Areas.Transparency.Controllers
  11. {
  12. public class TransparencyController : DefaultController
  13. {
  14. private TeknikEntities db = new TeknikEntities();
  15. [AllowAnonymous]
  16. public ActionResult Index()
  17. {
  18. ViewBag.Title = "Transparency - " + Config.Title;
  19. ViewBag.Description = "Teknik transparency and statistics.";
  20. TransparencyViewModel model = new TransparencyViewModel();
  21. Upload.Models.Upload upload = db.Uploads.OrderByDescending(u => u.UploadId).FirstOrDefault();
  22. model.UploadCount = (upload != null) ? upload.UploadId : 0;
  23. model.UploadSize = (upload != null) ? db.Uploads.Sum(u => (long)u.ContentLength) : 0;
  24. Paste.Models.Paste paste = db.Pastes.OrderByDescending(p => p.PasteId).FirstOrDefault();
  25. model.PasteCount = (paste != null) ? paste.PasteId : 0;
  26. Profile.Models.User user = db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
  27. model.UserCount = (user != null) ? user.UserId : 0;
  28. Shortener.Models.ShortenedUrl url = db.ShortenedUrls.OrderByDescending(s => s.ShortenedUrlId).FirstOrDefault();
  29. model.ShortenedUrlCount = (url != null) ? url.ShortenedUrlId : 0;
  30. model.TotalNet = new Dictionary<string, double>();
  31. var billSums = db.Transactions.OfType<Bill>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
  32. model.TotalBills = new Dictionary<string, double>();
  33. foreach (var sum in billSums)
  34. {
  35. model.TotalBills.Add(sum.currency, sum.total);
  36. if (model.TotalNet.ContainsKey(sum.currency))
  37. {
  38. model.TotalNet[sum.currency] += sum.total;
  39. }
  40. else
  41. {
  42. model.TotalNet.Add(sum.currency, sum.total);
  43. }
  44. }
  45. var oneSums = db.Transactions.OfType<OneTime>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
  46. model.TotalOneTimes = new Dictionary<string, double>();
  47. foreach (var sum in oneSums)
  48. {
  49. model.TotalOneTimes.Add(sum.currency, sum.total);
  50. if (model.TotalNet.ContainsKey(sum.currency))
  51. {
  52. model.TotalNet[sum.currency] += sum.total;
  53. }
  54. else
  55. {
  56. model.TotalNet.Add(sum.currency, sum.total);
  57. }
  58. }
  59. var donationSums = db.Transactions.OfType<Donation>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
  60. model.TotalDonations = new Dictionary<string, double>();
  61. foreach (var sum in donationSums)
  62. {
  63. model.TotalDonations.Add(sum.currency, sum.total);
  64. if (model.TotalNet.ContainsKey(sum.currency))
  65. {
  66. model.TotalNet[sum.currency] += sum.total;
  67. }
  68. else
  69. {
  70. model.TotalNet.Add(sum.currency, sum.total);
  71. }
  72. }
  73. model.Bills = db.Transactions.OfType<Bill>().OrderByDescending(b => b.DateSent).ToList();
  74. model.OneTimes = db.Transactions.OfType<OneTime>().OrderByDescending(b => b.DateSent).ToList();
  75. model.Donations = db.Transactions.OfType<Donation>().OrderByDescending(b => b.DateSent).ToList();
  76. model.Takedowns = db.Takedowns.OrderByDescending(b => b.DateRequested).ToList();
  77. return View(model);
  78. }
  79. }
  80. }