public ActionResult Solicitar(SoliciteContatoModel obj) { SoliciteContatoRepository rep = new SoliciteContatoRepository(); string emailFrom = System.Configuration.ConfigurationManager.AppSettings[name: "emailGuest"]; string emailTo = System.Configuration.ConfigurationManager.AppSettings[name: "email"]; string passwordEmailFrom = System.Configuration.ConfigurationManager.AppSettings[name: "senhaEmailGuest"]; if (rep.Save(obj: obj)) { TempData["Sucesso"] = "Solicitação Inserida com sucesso!"; if (!string.IsNullOrEmpty(value: emailFrom) && !string.IsNullOrEmpty(value: emailTo) && !string.IsNullOrEmpty(value: passwordEmailFrom)) { StringBuilder sb = new StringBuilder(); sb.Append(value: obj.xNomeEmpresa + " solicitou contato"); sb.AppendLine(); sb.Append(value: "Id solicitação: " + obj.idSolicitacao); HlpEmail email = new HlpEmail(_objSettings: new SettingsEmail { enableSsl = false, host = "smtp.hlp.com.br", nPort = 587 }); email.SendEmail(mailFrom: emailFrom, mailTo: emailTo, xSubject: "Aviso de Solicitação!", xBody: sb.ToString(), xPassword: passwordEmailFrom); } return RedirectToAction("Home", "Home"); } return View(); }
public bool Save(SoliciteContatoModel obj) { using (var con = new PortalEntities()) { tb_solicitecontato objTbSolicitacao = new tb_solicitecontato { stObjetivo = obj.stObjetivo, xCelular = obj.xCelular, xEmail = obj.xEmail, xMessage = obj.xMessage, xTelefone = obj.xTelefone, xNomeEmpresa = obj.xNomeEmpresa, stContatoPreferencial = obj.stContatoPreferencial }; con.tb_solicitecontato.Add(entity: objTbSolicitacao); try { con.SaveChanges(); obj.idSolicitacao = objTbSolicitacao.idSoliciteContato; return true; } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } }