public int UpdateQuote(QuoteViewModel quote) { DailyQuote DBQuote = DAManager.QuotesRepository.Get(q => q.QuoteId == quote.QuoteId).FirstOrDefault(); if (DBQuote != null) { DBQuote.Quote = quote.Quote; DBQuote.Author = quote.Author; DBQuote.DayDate = quote.DayDate; } else { return(-1); } try { DAManager.Save(); return(DBQuote.QuoteId); } catch (Exception ex) { logService.WriteError(ex.Message, ex.Message, ex.StackTrace, ex.Source); return(-1); } }
public ActionResult DeleteConfirmed(int id) { DailyQuote dailyQuote = db.DailyQuotes.Find(id); db.DailyQuotes.Remove(dailyQuote); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,QuoteSource,QuoteType,Date,Value,Comments")] DailyQuote dailyQuote) { if (ModelState.IsValid) { db.Entry(dailyQuote).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dailyQuote)); }
// GET: DailyQuotes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DailyQuote dailyQuote = db.DailyQuotes.Find(id); if (dailyQuote == null) { return(HttpNotFound()); } return(View(dailyQuote)); }
private void buttonImportTxt_Click(object sender, EventArgs e) { if (openTxtFileDialog.ShowDialog() != DialogResult.OK) { return; } int pos = openTxtFileDialog.FileNames[0].LastIndexOf('\\'); string dirName = openTxtFileDialog.FileNames[0].Substring(0, pos); pos = dirName.LastIndexOf('\\'); string name = dirName.Substring(pos + 1, dirName.Length - pos - 1); List <DayItem> items = new List <DayItem>(); foreach (string fileName in openTxtFileDialog.FileNames) { List <DayItem> newItems = TextImporter.Import(fileName); items.AddRange(newItems); } DailyQuote theQuote = new DailyQuote(name, items); if (theQuote.DailyData == null || theQuote.DailyData.Count == 0) { return; } var quoteQuery = from quote in theQuote.DailyData select new { Time = quote.Date, quote.Open, quote.High, quote.Low, quote.Close }; quoteBindingSource.DataSource = quoteQuery.ToList(); TrendParser <DayItem> dailyParser = new TrendParser <DayItem>(10); List <TurningPoint <DayItem> > majors = dailyParser.PivotsOf(theQuote.DailyData); relationBindingSource.DataSource = majors; tabControl1.SelectedIndex = 2; }
public int AddNewQuote(QuoteViewModel quote) { DailyQuote DBQuote = new DailyQuote() { Author = quote.Author, DayDate = quote.DayDate, Quote = quote.Quote }; DAManager.QuotesRepository.Insert(DBQuote); try { DAManager.Save(); } catch (Exception ex) { logService.WriteError(ex.Message, ex.Message, ex.StackTrace, ex.Source); return(-1); } return(DBQuote.QuoteId); }
public void AddGoCompareToDb(string ConnectionString, string ConnectionStringTwo, string daysPast, string daysPastAlt, DateTime daysPastdb) { //Get values from GoCompare Home using (OleDbConnection objcn = new OleDbConnection { ConnectionString = ConnectionString }) { objcn.Open(); //reads all data and stores in datatable DataTable dtexcel = new DataTable(); OleDbDataAdapter adp = new OleDbDataAdapter("Select * From[QuotabilityPerformance-Datatabl$]", objcn); adp.Fill(dtexcel); dtexcel.Columns[1].ColumnName = "Date"; //Searches for row via date var res = from row in dtexcel.AsEnumerable() where (row.Field <string>("Date") == daysPastAlt) || (row.Field <string>("Date") == daysPast) select row; //stores into Array var newres = res.ToArray(); var date = newres[0]; // array values stores as variables to add to Database. var GCTotalQuotes = date.ItemArray[2].ToString(); var GCPartnerQuotes = date.ItemArray[4].ToString(); var GCTopQuote = date.ItemArray[13].ToString(); //var GCTopQuotesHIPercentage = Convert.ToString(Math.Round((Convert.ToDouble(date.ItemArray[14]) * 100), 2, MidpointRounding.ToEven)); //var GCQuotesBlockedPercentage = Convert.ToString(Math.Round((Convert.ToDouble(date.ItemArray[7]) * 100), 2, MidpointRounding.ToEven)); var GCTopQuotesHIPercentage = Convert.ToString(date.ItemArray[14]); var GCQuotesBlockedPercentage = Convert.ToString(date.ItemArray[7]); DailyPerformanceReportDbEntities1 db = new DailyPerformanceReportDbEntities1(); DailyQuote newQuote = new DailyQuote(); var QuoteSource = "Go Compare"; newQuote.Date = daysPastdb; newQuote.QuoteSource = QuoteSource; newQuote.QuoteType = "Total Quotes"; newQuote.Value = GCTotalQuotes; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Partner Quotes"; newQuote.Value = GCPartnerQuotes; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quote"; newQuote.Value = GCTopQuote; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes HI %"; newQuote.Value = GCTopQuotesHIPercentage; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Quotes Blocked %"; newQuote.Value = GCQuotesBlockedPercentage; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); } //Get Values from GoCompare Quote using (OleDbConnection objcn = new OleDbConnection { ConnectionString = ConnectionStringTwo }) { objcn.Open(); //reads all data and stores in datatable DataTable dtexcel = new DataTable(); OleDbDataAdapter adp = new OleDbDataAdapter("Select * From[QuotabilityPerformance-Datatabl$]", objcn); adp.Fill(dtexcel); dtexcel.Columns[1].ColumnName = "Date"; //Searches for row via date var res = from row in dtexcel.AsEnumerable() where (row.Field <string>("Date") == daysPastAlt) || (row.Field <string>("Date") == daysPast) select row; //stores into Array var newres = res.ToArray(); var date = newres[0]; // array values stores as variables to add to Database. var GCTopQuotesQPercentage = Convert.ToString(date.ItemArray[14]); //var GCTopQuotesQPercentage = Convert.ToString(Math.Round((Convert.ToDouble(date.ItemArray[14]) * 100), 2, MidpointRounding.ToEven)); //==== ADD TO DATABASE BELOW ======================== // DailyPerformanceReportDbEntities1 db = new DailyPerformanceReportDbEntities1(); DailyQuote newQuote = new DailyQuote(); var QuoteSource = "Go Compare"; var Date = daysPastdb; newQuote.Date = Date; newQuote.QuoteSource = QuoteSource; newQuote.QuoteType = "Top Quotes Q %"; newQuote.Value = GCTopQuotesQPercentage.ToString(); newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); } }
public void AddCTMToDb(OpenExcelFile cm1, ExcelColumnListByRowValue cm2, string fileLocation, ExcelCleanUp cm3, string daysPast, DateTime daysPastdb) { // open excel file Application xlApp = new Application(); Workbook xlWorkbook = xlApp.Workbooks.Open(@fileLocation); Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Range xlRange = xlWorksheet.UsedRange; // returns list of colum values based on search value. var columnList = cm2.RetrieveColumnByRow(xlWorksheet, daysPast); var newlist = columnList[0]; var CTMConsumerEnquiries = newlist[7].ToString(); var CTMPricesPresented = newlist[8].ToString(); var CTMPricesPresentedP1 = newlist[9].ToString(); var CTMClickThroughPCTs = newlist[11].ToString(); var CTMTopQuotesPercentage = Convert.ToString(Math.Round((Convert.ToDouble(newlist[21]) * 100), 2, MidpointRounding.ToEven)); var CTMQuotesDeclinePercentage = Convert.ToString(Math.Round((Convert.ToDouble(newlist[15]) * 100), 2, MidpointRounding.ToEven)); //add to database DailyPerformanceReportDbEntities1 db = new DailyPerformanceReportDbEntities1(); DailyQuote newQuote = new DailyQuote(); var QuoteSource = "Compare The Market"; var Date = DateTime.Today.Date; newQuote.Date = daysPastdb; newQuote.QuoteSource = QuoteSource; newQuote.QuoteType = "Consumer Enquiries"; newQuote.Value = CTMConsumerEnquiries; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Prices Presented"; newQuote.Value = CTMPricesPresented; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Prices Presented @P1"; newQuote.Value = CTMPricesPresentedP1; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Click Through (PCTs)"; newQuote.Value = CTMClickThroughPCTs; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes %"; newQuote.Value = CTMTopQuotesPercentage; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Quotes Declined %"; newQuote.Value = CTMQuotesDeclinePercentage; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); // close excel file GC.Collect(); GC.WaitForPendingFinalizers(); //release com objects to fully kill excel process from running in the background Marshal.ReleaseComObject(xlRange); Marshal.ReleaseComObject(xlWorksheet); //close and release xlWorkbook.Close(true, fileLocation, Missing.Value); Marshal.ReleaseComObject(xlWorkbook); //quit and release xlApp.Quit(); Marshal.ReleaseComObject(xlApp); //Process[] processes = Process.GetProcessesByName("EXCEL"); //foreach (Process p in processes) //{ // p.Kill(); //} }
public void AddMSToDb(string daysPast, DateTime daysPastDb, string ConnectionString) { using (OleDbConnection objcn = new OleDbConnection { ConnectionString = ConnectionString }) { objcn.Open(); //reads all data and stores in datatable DataTable dtexcel = new DataTable(); OleDbDataAdapter adp = new OleDbDataAdapter("Select * From[$Data]", objcn); adp.Fill(dtexcel); dtexcel.Columns[0].ColumnName = "Date"; DailyPerformanceReportDbEntities1 db = new DailyPerformanceReportDbEntities1(); var res = from row in dtexcel.AsEnumerable() where row.Field <string>("Date") == daysPast select row; if (res == null || !res.Any()) { throw new ArgumentNullException("value", "not"); } var newres = res.ToArray(); var date = newres[0]; var MSTopQuotes = date.ItemArray[8].ToString(); var MSTotalQueries = date.ItemArray[3].ToString(); var MSTotalQuotesReturned = date.ItemArray[4].ToString(); var MSTotalClicks = date.ItemArray[5].ToString(); var MSProviderQuoteRatePercentage = date.ItemArray[6].ToString(); var MSFilteredQuotes = date.ItemArray[7].ToString(); DailyQuote newQuote = new DailyQuote(); var QuoteSource = "Money Supermarket"; newQuote.Date = daysPastDb; newQuote.QuoteSource = QuoteSource; newQuote.QuoteType = "Total Queries"; newQuote.Value = MSTotalQueries; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Total Quotes Returned"; newQuote.Value = MSTotalQuotesReturned; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Total Clicks"; newQuote.Value = MSTotalClicks; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Provider Quote Rate %"; newQuote.Value = MSProviderQuoteRatePercentage; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Filtered Quotes"; newQuote.Value = MSFilteredQuotes; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes"; newQuote.Value = MSTopQuotes; newQuote.Comments = null; db.DailyQuotes.Add(newQuote); db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Id,QuoteSource,QuoteType,Date,Value,Comments,TQValue,TQComments,PQValue,TopQValue,TopQComments,PQComments,QBValue,QBComments ,TopQuote,TopQuoteComments,TopQuoteHI,TopQuoteHIComments,TopQuoteQ,TopQuoteQComments,ClickThrough,ClickThroughComments,TotalQueries,TotalQuotesReturned,TotalClicks,ProviderQuoteRate,FilteredQuotes,TotalQueriesComments,TotalQuotesReturnedComments,TotalClicksComments,ProviderQuoteRateComments,FilteredQuotesComments,TopQuotes,TopQuotesComments")] DailyQuoteTable dailyQuote) { if (ModelState.IsValid) { if (dailyQuote.QuoteSource == "Confused" || dailyQuote.QuoteSource == "Go Compare") { DailyQuote newQuote = new DailyQuote(); newQuote.Date = dailyQuote.Date; newQuote.QuoteSource = dailyQuote.QuoteSource; newQuote.QuoteType = "Total Quotes"; newQuote.Value = dailyQuote.TQValue; newQuote.Comments = dailyQuote.TQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Partner Quotes"; newQuote.Value = dailyQuote.PQValue; newQuote.Comments = dailyQuote.PQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quote"; newQuote.Value = dailyQuote.TopQValue; newQuote.Comments = dailyQuote.TopQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes Q %"; newQuote.Value = dailyQuote.TopQuoteQ; newQuote.Comments = dailyQuote.TopQuoteQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes HI %"; newQuote.Value = dailyQuote.TopQuoteHI; newQuote.Comments = dailyQuote.TopQuoteHIComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Quotes Blocked %"; newQuote.Value = dailyQuote.QBValue; newQuote.Comments = dailyQuote.QBComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); } if (dailyQuote.QuoteSource == "Compare The Market") { DailyQuote newQuote = new DailyQuote(); newQuote.Date = dailyQuote.Date; newQuote.QuoteSource = dailyQuote.QuoteSource; newQuote.QuoteType = "Consumer Enquiries"; newQuote.Value = dailyQuote.TQValue; newQuote.Comments = dailyQuote.TQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Prices Presented"; newQuote.Value = dailyQuote.PQValue; newQuote.Comments = dailyQuote.PQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Prices Presented @P1"; newQuote.Value = dailyQuote.TopQValue; newQuote.Comments = dailyQuote.TopQComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Click Through (PCTs)"; newQuote.Value = dailyQuote.ClickThrough; newQuote.Comments = dailyQuote.ClickThroughComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes %"; newQuote.Value = dailyQuote.TopQuote; newQuote.Comments = dailyQuote.TopQuoteComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Quotes Declined %"; newQuote.Value = dailyQuote.QBValue; newQuote.Comments = dailyQuote.QBComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); } if (dailyQuote.QuoteSource == "Money Supermarket") { DailyQuote newQuote = new DailyQuote(); newQuote.Date = dailyQuote.Date; newQuote.QuoteSource = dailyQuote.QuoteSource; newQuote.QuoteType = "Total Queries"; newQuote.Value = dailyQuote.TotalQueries; newQuote.Comments = dailyQuote.TotalQueriesComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Total Quotes Returned"; newQuote.Value = dailyQuote.TotalQuotesReturned; newQuote.Comments = dailyQuote.TotalQuotesReturnedComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Total Clicks"; newQuote.Value = dailyQuote.TotalClicks; newQuote.Comments = dailyQuote.TotalClicksComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Provider Quote Rate %"; newQuote.Value = dailyQuote.ProviderQuoteRate; newQuote.Comments = dailyQuote.ProviderQuoteRateComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Filtered Quotes"; newQuote.Value = dailyQuote.FilteredQuotes; newQuote.Comments = dailyQuote.FilteredQuotesComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); newQuote.QuoteType = "Top Quotes"; newQuote.Value = dailyQuote.TopQuotes; newQuote.Comments = dailyQuote.TopQuoteComments; db.DailyQuotes.Add(newQuote); db.SaveChanges(); } return(RedirectToAction("Index")); } ModelState.AddModelError("QuoteSource", "Please Select the Date"); ViewBag.QSourceList = GetQuoteSource(); ViewData["QSourceList"] = GetQuoteSource(); return(View(dailyQuote)); }
public string SendEmail() { DateTime _endDate = DateTime.Today.Date.AddDays(-35); MailAddress _From = new MailAddress("*****@*****.**"); MailAddress _To = new MailAddress("*****@*****.**"); //MailAddress _From = new MailAddress("*****@*****.**"); //MailAddress _To = new MailAddress("*****@*****.**"); MailMessage _Mail = new MailMessage(_From, _To); _Mail.To.Add("*****@*****.**"); _Mail.To.Add("*****@*****.**"); _Mail.IsBodyHtml = true; _Mail.Subject = "DailyPerformance Report"; string _html = ""; string path = HttpContext.Server.MapPath("~/Views/DailyQuotes/SendEmail.cshtml"); var template = System.IO.File.ReadAllText(path); RazorEngine.Templating.DynamicViewBag _ViewBag = new RazorEngine.Templating.DynamicViewBag(); _ViewBag.AddValue("test", "test data"); List <DailyQuote> result = new List <DailyQuote>(); GetCTQ(); _ViewBag.AddValue("_CTQDatestring", _Dstring); _ViewBag.AddValue("_CTQ", _CTopQuote); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Confused" && x.QuoteType == "Partner Quotes").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_PTQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Confused" && x.QuoteType == "Top Quote").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTopQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Confused" && x.QuoteType == "Top Quotes Q %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTopQP", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Confused" && x.QuoteType == "Top Quotes HI %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTopHIP", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Confused" && x.QuoteType == "Quotes Blocked %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CQBP", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Go Compare" && x.QuoteType == "Total Quotes").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_GTQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Go Compare" && x.QuoteType == "Partner Quotes").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_GPQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Go Compare" && x.QuoteType == "Top Quote").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_GTopQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Go Compare" && x.QuoteType == "Top Quotes Q %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_GTopQP", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Go ComPare" && x.QuoteType == "Top Quotes HI %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_GTopHIP", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Go Compare" && x.QuoteType == "Quotes Blocked %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_GQBP", GetData(result, true)); //compare the Market result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Compare The Market" && x.QuoteType == "Consumer Enquiries").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTMCE", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Compare The Market" && x.QuoteType == "Prices Presented").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTMPP", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Compare The Market" && x.QuoteType == "Prices Presented @P1").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTMPP1", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Compare The Market" && x.QuoteType == "Click Through (PCTs)").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTMCT", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Compare The Market" && x.QuoteType == "Top Quotes %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTMTQP", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Compare The Market" && x.QuoteType == "Quotes Declined %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_CTMQD", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Money Supermarket" && x.QuoteType == "Total Queries").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_MSMTQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Money Supermarket" && x.QuoteType == "Total Quotes Returned").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_MSMTQR", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Money Supermarket" && x.QuoteType == "Total Clicks").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_MSMTC", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Money Supermarket" && x.QuoteType == "Provider Quote Rate %").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_MSMPQR", GetData(result, true)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Money Supermarket" && x.QuoteType == "Filtered Quotes").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_MSMFQ", GetData(result, false)); result = db.DailyQuotes.Where(x => x.Date <= DateTime.Today.Date && x.Date >= _endDate && x.QuoteSource == "Money Supermarket" && x.QuoteType == "Top Quotes").OrderByDescending(x => x.Date).ToList(); _ViewBag.AddValue("_MSMTQS", GetData(result, false)); DailyQuote model = new DailyQuote(); var config = new TemplateServiceConfiguration { Language = Language.CSharp, EncodedStringFactory = new RawStringFactory() }; config.EncodedStringFactory = new HtmlEncodedStringFactory(); var service = RazorEngineService.Create(config); Engine.Razor = service; // _html= Razor.Parse(template,model,_ViewBag,null); var templateService = new TemplateService(config); _html = Engine.Razor.RunCompile(template, "Email", null, null, _ViewBag); _Mail.Body = _html; SmtpClient smtp = new SmtpClient { Port = 25, Host = "auth.smtp.1and1.co.uk", Credentials = new NetworkCredential("*****@*****.**", "paragon") }; smtp.Send(_Mail); return("<h2>Email Sent</h2>"); }