/// <summary> /// Deprecated Method for adding a new object to the Order EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrder(Order order) { base.AddObject("Order", order); }
public ActionResult Order(OrderFormModel orderFormModel) { if (ModelState.IsValid) { try { using (var context = new SiteContainer()) { var order = new Order { Address = orderFormModel.Address, Email = orderFormModel.Email, Name = orderFormModel.Name, Phone = orderFormModel.Phone, Size = orderFormModel.Size }; //var size = orderFormModel.Size.FirstOrDefault(s => s.Selected); //if (size != null) //{ // order.Size = size.Text; //} context.AddToOrder(order); context.SaveChanges(); } string defaultMailAddressFrom = ConfigurationManager.AppSettings["feedbackEmailFrom"]; string defaultMailAddresses = ConfigurationManager.AppSettings["feedbackEmailsTo"]; string subject = ConfigurationManager.AppSettings["orderMailSubject"]; string displayName = ConfigurationManager.AppSettings["orderDisplayName"]; var emailFrom = new MailAddress(defaultMailAddressFrom, displayName); var emailsTo = defaultMailAddresses .Split(new[] { ";", " ", "," }, StringSplitOptions.RemoveEmptyEntries) .Select(s => new MailAddress(s)) .ToList(); var result = Helpers.MailHelper.SendOrderTemplate(emailFrom, emailsTo, subject, "OrderTemplate.htm", null, true, orderFormModel.Name, string.IsNullOrEmpty(orderFormModel.Email) ? "[не указано]" : orderFormModel.Email, orderFormModel.Phone, orderFormModel.Address,orderFormModel.Size,orderFormModel.ProductId,orderFormModel.ProductTitle); if (result.EmailSent) return PartialView("SuccessOrder"); orderFormModel.ErrorMessage = "Ошибка: " + result.ErrorMessage; } catch (Exception ex) { orderFormModel.ErrorMessage = ex.Message; if (ex.InnerException != null) orderFormModel.ErrorMessage += " " + ex.InnerException.Message; } } return PartialView("OrderForm", orderFormModel); }
/// <summary> /// Create a new Order object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static Order CreateOrder(global::System.Int32 id) { Order order = new Order(); order.Id = id; return order; }