// working on this public FileResult SpecificCategoryReferralsByDateFile(SpecificCategoryReferralsByDateVM input) { if (ModelState.IsValid) { input = reportManager.SpecificCategoryReferralsByDateFileSearch(input); var file = ImportExportHelper.exportToCsv(input.result, true); // alert, if the only object is the info about Date period if (input.result.Count() != 0) { return(File(file.FullName, "Application/octet-stream", file.Name)); } else { this.Response.Write("<script> alert('No Data found based on the criteria!'); window.history.back(); </script>"); } } else { this.Response.Write("<script> alert('Plese input valid dates!'); window.history.back(); </script>"); } return(null); }
// Category Referral By Date Feature ------------------------------------ public ActionResult SpecificCategoryReferralsByDate(SpecificCategoryReferralsByDateVM categoryModel) { return(PartialView("_SpecificCategoryReferralsByDate", categoryModel)); }
public SpecificCategoryReferralsByDateVM SpecificCategoryReferralsByDateFileSearch(SpecificCategoryReferralsByDateVM input) { var fromDate = input.fDate.AddDays(-1); var toDate = input.tDate.AddDays(1); int categoryID = ReportManager.getCategoryId(input.categoryName); using (var db = new MainDb()) { var query = db.referrals .Include(i => i.companyCategoryType) .Include(p => p.company) .Include(q => q.client) .Include(w => w.client.contactInfo) .Where(e => (e.companyCategoryTypeId == categoryID) && (e.referralDate > fromDate) && (e.referralDate < toDate)).ToList(); input.result = query.ToList <object>(); if (input.result.Count() != 0) { var items = new List <object> { new { PERIOD = fromDate.ToShortDateString() + " thru " + toDate.ToShortDateString() } }; items.Add(new { Client = "Count of Referrals: " + (input.result.Count()) }); items.Add( new { h1 = "Category Name", h2 = "Company Name", h3 = "Client Name", h4 = "Referral Date", h5 = "Quote", h6 = "Commission", h7 = "Service description" }); var item2 = query.Select(i => new { Category = (i.companyCategoryType.name != null ? i.companyCategoryType.name : "N/A"), CompanyName = (i.company.name != null ? i.company.name : "N/A"), ClientName = ((i.client.contactInfo != null) && (i.client.contactInfo.name != null) ? i.client.contactInfo.name : "N/A"), ReferralDate = (i.created != null ? i.created.ToShortDateString() : "N/A"), Quote = (i.quote != null ? i.quote : 0), Commission = (i.commissionAmount != null ? i.commissionAmount : 0), Servicedescription = (i.description != null ? i.description : "N/A") }).ToList <object>(); foreach (var i in item2) { items.Add(i); } input.result = items; } return(input); } }