public ActionResult Create() { ViewData["StatusList"] = new SelectList(new[] { "Open", "Send", "Received", "Shipped", "Completed" } .Select(x => new { value = x, text = x }), "value", "text", "Open"); Quote quote = new Quote(); quote.ShipDate = System.DateTime.Now; return View(quote); }
public ActionResult Create(Quote quote) { try { quote.CreationDate = System.DateTime.Now; db.Quotes.Add(quote); db.SaveChanges(); MailMessage Msg = new MailMessage(); Msg.From = new MailAddress(ConfigurationManager.AppSettings["Email"]); StreamReader reader = new StreamReader(Server.MapPath("~/SendMail.html")); string readFile = reader.ReadToEnd(); string StrContent = ""; StrContent = readFile; //Here replace the name with [MyName] StrContent = StrContent.Replace("[Reference]", quote.ReferenceNo); StrContent = StrContent.Replace("[PickUpLocation]", quote.PickupLocation); StrContent = StrContent.Replace("[DeliveryLocation]", quote.DeliveryLocation); StrContent = StrContent.Replace("[ShipDate]", quote.ShipDate.ToShortDateString()); StrContent = StrContent.Replace("[Description]", quote.Description); StrContent = StrContent.Replace("[Comments]", quote.Comments); Msg.Subject = string.Format("Subject – Request Quote – Reference# {0}", quote.ReferenceNo); Msg.Body = StrContent.ToString(); Msg.IsBodyHtml = true; // your remote SMTP server IP. SmtpClient smtp = new SmtpClient(); smtp.Host = ConfigurationManager.AppSettings["MailServer"]; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); NetworkCred.UserName = ConfigurationManager.AppSettings["Email"]; NetworkCred.Password = ConfigurationManager.AppSettings["Password"]; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = int.Parse(ConfigurationManager.AppSettings["MailPort"]); smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSSLEnabled"].ToString()); List<Vender> vendorList = db.Venders.Where(x => x.IsActive == true).ToList(); string userState = "test message1"; foreach (var item in vendorList) { Msg.To.Add(item.Email); smtp.Send(Msg); } return RedirectToAction("List"); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(Quote quote) { db.Quotes.Attach(quote); db.SaveChanges(); return RedirectToAction("List"); }
public async Task<ActionResult> Create(Quote quote) { try { Quote oldQuote = db.Quotes.Where(x => x.ReferenceNo == quote.ReferenceNo).SingleOrDefault(); if (oldQuote == null) { quote.CreationDate = System.DateTime.Now; db.Quotes.Add(quote); db.SaveChanges(); MailMessage Msg = new MailMessage(); Msg.From = new MailAddress(ConfigurationManager.AppSettings["Email"]); StreamReader reader = new StreamReader(Server.MapPath("~/SendMail.html")); string readFile = reader.ReadToEnd(); string StrContent = ""; StrContent = readFile; //Here replace the name with [MyName] StrContent = StrContent.Replace("[PickUpLocation]", quote.PickupLocation); StrContent = StrContent.Replace("[DeliveryLocation]", quote.DeliveryLocation); StrContent = StrContent.Replace("[ShipDate]", quote.ShipDate.ToShortDateString()); StrContent = StrContent.Replace("[Description]", quote.Description); Msg.Subject = string.Format("Request Quote – Reference# {0}", quote.ReferenceNo); Msg.Body = StrContent.ToString(); Msg.IsBodyHtml = true; // your remote SMTP server IP. SmtpClient smtp = new SmtpClient(); smtp.Host = ConfigurationManager.AppSettings["MailServer"]; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); NetworkCred.UserName = ConfigurationManager.AppSettings["Email"]; NetworkCred.Password = ConfigurationManager.AppSettings["Password"]; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = int.Parse(ConfigurationManager.AppSettings["MailPort"]); smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSSLEnabled"].ToString()); List<Vender> vendorList = db.Venders.Where(x => x.IsActive == true).ToList(); foreach (var item in vendorList) { Msg.To.Add(item.Email); } Msg.To.Add(new MailAddress(ConfigurationManager.AppSettings["ToEmail"])); //smtp.Send(Msg); await smtp.SendMailAsync(Msg); return RedirectToAction("List"); } else { ViewData["StatusList"] = new SelectList(new[] { "Open", "Quote Send", "Quote Received", "Shipped", "Completed" } .Select(x => new { value = x, text = x }), "value", "text"); return View(quote); } } catch (Exception ex) { throw ex; } }
public ActionResult Edit(Quote quote) { db.Quotes.Attach(quote); var entry = db.Entry(quote); entry.State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("List"); }
public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, Quote quote) { db.Quotes.Attach(quote); var entry = db.Entry(quote); entry.State = EntityState.Modified; db.SaveChanges(); return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet); }