public void CreateFromAdmin(Order order) { if (order == null) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); orderRepository.InsertOrUpdate(order); orderRepository.Save(); }
public void Create(Order order) { if(order == null) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); orderRepository.InsertOrUpdateWithPerson(order, User.Identity.Name); orderRepository.Save(); }
public virtual MailMessage OrderSent(string userEmail, Order order) { var mailMessage = new MailMessage { Subject = "Заказ отправлен" }; ViewBag.order = order; mailMessage.To.Add(userEmail); PopulateBody(mailMessage, viewName: "OrderSent"); return mailMessage; }
public void DeletedDetails(Order order, IEnumerable<int> deleted_detail_list) { for (int i = 0; i < deleted_detail_list.Count() - 1; i++) { OrderDetail detail = context.OrderDetails.Find(deleted_detail_list.ElementAt(i)); if (detail != null) context.OrderDetails.Remove(detail); } //CreditOperation cp = context.CreditOperations.SingleOrDefault(o => o.Order.Id == order.Id); //if (cp != null) // cp.Amount = order.OrderDetail.Sum(od => od.Product.Price * od.Quantity); //order.Person.CalculateBalance(); if (order.OrderDetail.Count == 0) { order.Statuses.Clear(); context.Orders.Remove(order); } }
private dynamic Order_(Order order) { dynamic dynamic_order = new JsonObject(); dynamic_order.Id = order.Id; dynamic_order.Date = order.Date; dynamic_order.CurrentStatus = order.Statuses.SingleOrDefault(s => s.isCurrent).StatusValue; dynamic_order.Person = Person_(order.Person); dynamic details = new JsonArray(); foreach (OrderDetail detail in order.OrderDetail) { dynamic json_detail = new JsonObject(); json_detail.Id = detail.Id; json_detail.Quantity = detail.Quantity; dynamic product = new JsonObject(); product.Id = detail.Product.Id; product.Price = detail.Product.Price; product.Summary = detail.Product.Summary; product.Title = detail.Product.Title; product.isComplex = detail.Product.isComplex; json_detail.Product = product; details.Add(json_detail); } dynamic_order.OrderDetail = details; return dynamic_order; }
private string GetOrderJsonValue(Order order) { return Order_(order).ToString(); }
public void InsertOrUpdate(Order order) { if (order.Id == default(int)) { // New entity foreach (var detail in order.OrderDetail) { detail.Product = context.Products.Find(detail.Product.Id); } order.Statuses.Add(new OrderStatus { Date = DateTime.Now, isCurrent = true, StatusValue = (int)OrderStatusValue.Order }); context.Orders.Add(order); } else { foreach (var detail in order.OrderDetail) { detail.Product = context.Products.Find(detail.Product.Id); context.Entry(detail).State = EntityState.Modified; if (detail.Id == default(int)) { context.OrderDetails.Add(detail); } } context.Entry(order).State = EntityState.Modified; } }
public void InsertOrUpdateWithPerson(Order order, string domainName) { if (order.Id == default(int)) { Person person = context.People.SingleOrDefault(p => p.DomainName == domainName); order.Person = person; foreach (var detail in order.OrderDetail) { detail.Product = context.Products.Find(detail.Product.Id); } order.Statuses.Add(new OrderStatus { Date = DateTime.Now, isCurrent = true, StatusValue = (int)OrderStatusValue.Order }); //decimal amount = order.OrderDetail.Sum(od => od.Product.Price * od.Quantity); //person.Operations.Add(new CreditOperation { Date = DateTime.Now, Order = order, Amount = amount, Summary = "Заказ" }); //person.CalculateBalance(); context.Orders.Add(order); } else { //Person person = context.People.SingleOrDefault(p => p.DomainName == domainName); //order.Person = person; foreach (var detail in order.OrderDetail) { detail.Product = context.Products.Find(detail.Product.Id); context.Entry(detail).State = EntityState.Modified; if (detail.Id == default(int)) { context.OrderDetails.Add(detail); } } //CreditOperation operation = context.CreditOperations.SingleOrDefault(o => o.Order.Id == order.Id); //operation.Amount = order.OrderDetail.Sum(od => od.Product.Price * od.Quantity); //order.Person.CalculateBalance(); //context.Entry(operation).State = EntityState.Modified; context.Entry(order).State = EntityState.Modified; } }