public async Task <ActionResult> Add(EmailTemplateVm data) { try { if (!ModelState.IsValid) { return(View(data)); } using (_db = new DBEntities()) { var emailTemplate = new EmailTemplete { Name = data.Name, Subject = data.Subject, Body = data.Body, FromId = data.FromId, BccId = data.BccId, HashTag = data.HashTag, CreatedDate = DateTime.UtcNow, CreatedBy = User.Identity.GetUserId() }; _db.Entry(emailTemplate).State = EntityState.Added; await _db.SaveChangesAsync(); } TempData["Success"] = SuccessMessage.Added; return(RedirectToAction("Index", "EmailTemplate", new { area = "ControlPanel" })); } catch (Exception e) { TempData["Error"] = e.Message; return(View()); } }
public async Task <ActionResult> Edit(long id) { try { using (_db = new DBEntities()) { var emailTemplate = await _db.EmailTempletes.FindAsync(id); if (emailTemplate == null) { ModelState.AddModelError("", ErrorMessage.DataNotFound); return(View()); } else { var emailTemplateVm = new EmailTemplateVm { EmailTempleteId = emailTemplate.EmailTempleteId, Name = emailTemplate.Name, Subject = emailTemplate.Subject, Body = emailTemplate.Body, HashTag = emailTemplate.HashTag, FromId = emailTemplate.FromId, BccId = emailTemplate.BccId }; return(View(emailTemplateVm)); } } } catch (Exception e) { TempData["Error"] = e.Message; return(View()); } }
public async Task <ActionResult> Edit(EmailTemplateVm data) { try { if (!ModelState.IsValid) { return(View(data)); } using (_db = new DBEntities()) { var emailTemplate = await _db.EmailTempletes.FindAsync(data.EmailTempleteId); if (emailTemplate == null) { ModelState.AddModelError("", ErrorMessage.DataNotFound); return(View()); } else { emailTemplate.Name = data.Name; emailTemplate.Subject = data.Subject; emailTemplate.Body = data.Body; emailTemplate.FromId = data.FromId; emailTemplate.BccId = data.BccId; emailTemplate.HashTag = data.HashTag; emailTemplate.UpdatedDate = DateTime.UtcNow; emailTemplate.UpdatedBy = StaticValues.UserId;//Static UserId _db.Entry(emailTemplate).State = EntityState.Modified; _db.SaveChanges(); } } TempData["Success"] = SuccessMessage.Updated; return(RedirectToAction("Index", "EmailTemplate", new { area = "ControlPanel" })); } catch (Exception e) { TempData["Error"] = e.Message; return(View()); } }