public ActionResult Edit([Bind(Include = "ID,EmailAddress,Password,Port,Host,EnabledSSL,TemplateID,CreatedAt,UpdatedAt,Active")] MailConfig mailConfig) { try { var validateName = _mailConfigService.GetAll().FirstOrDefault (x => x.EmailAddress == mailConfig.EmailAddress && x.ID != mailConfig.ID); if (validateName != null) { ModelState.AddModelError("EmailAddress", "Email Address already exists"); } if (ModelState.IsValid) { string password = MailHelper.Encrypt(mailConfig.Password); mailConfig.Password = password; mailConfig.UpdatedAt = DateTime.Now; db.Entry(mailConfig).State = EntityState.Modified; db.SaveChanges(); SetAlert("Update Mail Config success", "success"); return(RedirectToAction("Index")); } }catch (Exception e) { SetAlert("Update Mail Config error", "error"); } return(View(mailConfig)); }