public static Customer GetCustomerByKey(string id) { Customer oCustomer = new Customer(); try { using (var ctx = new PollaExpressDBEntities()) { ctx.Configuration.ProxyCreationEnabled = false; oCustomer = ctx.Customer.Where(x => x.id == id).FirstOrDefault(); } } catch (Exception ex) { throw ex; } return oCustomer; }
public static void SaveCustomer(Customer customer) { try { using (var ctx = new PollaExpressDBEntities()) { //verify if the student exists Customer oCustomer = GetCustomerByKey(customer.id); if (oCustomer != null) { // if exists then edit ctx.Customer.Attach(oCustomer); EntityFrameworkHelper.EnumeratePropertyDifferences(oCustomer, customer); ctx.SaveChanges(); } else { // else create ctx.Customer.Add(customer); ctx.SaveChanges(); } } } catch (DbEntityValidationException e) { StringBuilder oError = new StringBuilder(); foreach (var eve in e.EntityValidationErrors) { oError.AppendLine(string.Format("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) { oError.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } string msg = oError.ToString(); throw new Exception(msg); } catch (Exception ex) { throw ex; } }
private void SendMail(Customer cliente, int idPartido, string ganadores, string rootPath) { Game partido = GameCRUD.GetGameByKey(idPartido); // send notification List<System.Net.Mail.MailAddress> to = new List<System.Net.Mail.MailAddress>(); if (ConfigurationManager.AppSettings["testMail"].ToString() == "N") to.Add(new System.Net.Mail.MailAddress(cliente.email)); else to.Add(new System.Net.Mail.MailAddress("*****@*****.**")); Dictionary<string, string> dynamicValues = new Dictionary<string, string>(); dynamicValues.Add("[Cliente]", cliente.nombre); dynamicValues.Add("[Partido]", string.Format("{0} vs {1} del día {2}", partido.team1, partido.team2, partido.gameDate.ToString("yyyy-MM-dd"))); dynamicValues.Add("[Ganadores]", ganadores); MailingHelper.SendMail(to, string.Format("Ganadores partido {0} vs {1} del día {2}", partido.team1, partido.team2, partido.gameDate.ToString("yyyy-MM-dd")), rootPath + ConfigurationManager.AppSettings["emailGanadorHtml"].ToString(), rootPath + ConfigurationManager.AppSettings["emailGanadorTxt"].ToString(),"", dynamicValues); }
public void SaveCustomer(Customer customer) { CustomerCRUD.SaveCustomer(customer); }