public ActionResult Dashboard(string search, string month) { if (month == "") { month = null; } if (search == "") { search = null; } int ms = Convert.ToInt32(month); var months = Enumerable.Range(0, 7) .Select(i => DateTime.Now.AddMonths(i - 6)) .Select(date => date.ToString("MM")); AdminDashboardViewModel model = new AdminDashboardViewModel { PublishedCount = _context.GetPublishedNotesCount(), NumberOfDownload = _context.GetLastSevenDaysDownload(), NumberOfReg = _context.GetLastSevenDaysNewRegistration(), PublishedNotes = _context.GetAdminSearchedPublishedNotes(search, ms), LastSixMonth = months.Reverse(), month = month, searchNote = search }; if (search == null && month == null) { model.month = DateTime.Now.ToString("MM"); } foreach (var note in model.PublishedNotes) { if (note.IsPaid) { note.SellType = "Paid"; } else { note.SellType = "Free"; } if (note.Price == null) { note.Price = 0; } note.NumberOfDownloads = _context.GetNumberOfDownloads(note.Id); FileInfo file = new FileInfo(note.AttachmentPath); long fileSize = file.Length; double tera = Math.Pow(1024, 4); double giga = Math.Pow(1024, 3); double mega = Math.Pow(1024, 2); double kilo = Math.Pow(1024, 1); if (fileSize > tera) { note.AttachmentSize = ((float)(fileSize / tera)).ToString("0.00 TB"); } else if (fileSize > giga) { note.AttachmentSize = ((float)(fileSize / giga)).ToString("0.00 GB"); } else if (fileSize > mega) { note.AttachmentSize = ((float)(fileSize / mega)).ToString("0.00 MB"); } else if (fileSize > kilo) { note.AttachmentSize = (fileSize / kilo).ToString("0.00 KB"); } else { note.AttachmentSize = fileSize + " Bytes"; } } return(View(model)); }