public void UpdateItems(Order obj) { foreach (var item in obj.OrderItems) { if (_OrderItemService.GetById(item.Id) != null) { _OrderItemService.Remove(item.Id); } item.Product = null; _OrderItemService.Add(item); } }
public override ServiceResult <Order> Add(Order item) { item.ID = Guid.NewGuid().ToString("N"); item.OrderStatus = (int)OrderStatus.UnPaid; ServiceResult <Order> result = base.Add(item); if (!result.HasViolation) { foreach (var orderItem in item.OrderItems) { orderItem.OrderId = item.ID; _orderItemService.Add(orderItem); } } _eventManager.Trigger(Events.OnPendingOrderCreated, item); return(result); }
public ActionResult Checkout(OrderVm order) { if (!ModelState.IsValid) { return(View(order)); } var cartCookie = CheckCart(); if (cartCookie.Value != "") { var listItems = JsonConvert.DeserializeObject <List <OrderItemVm> >(cartCookie.Value); var newOrderItem = Mapper.Map <List <OrderItem> >(listItems); var newOrder = new Order(); newOrder.UpdateOrder(order); newOrder.CreatedDate = DateTimeOffset.UtcNow; _uow.BeginTran(); _orderService.Add(newOrder); foreach (var item in newOrderItem) { item.FromDate = item.FromDate.Date; //item.ToDate = item.ToDate.Date; item.OrderId = newOrder.Id; } _orderItemService.Add(newOrderItem); _uow.CommitTran(); cartCookie.Expires = DateTime.Now.AddDays(-180); Response.Cookies.Add(cartCookie); if (!string.IsNullOrEmpty(order.CustomerEmail)) { var settings = this.WebSetting; MailHelper.SendMail(order.CustomerEmail, "Đặt chỗ tại Global Trip", "Cám ơn bạn đã đặt chỗ, chúng tôi sẽ liên lạc trong thời gian sớm nhất" , settings.EmailAdmin , settings.PasswordEmail , "CÔNG TY TNHH THƯƠNG MẠI VÀ DỊCH VỤ DU LỊCH LỮ HÀNH TOÀN CẦU"); MailHelper.SendMail(this.WebSetting.EmailAdmin, "Đặt chỗ trên web Global Trip", "Khách hàng " + order.CustomerName + " đã đặt chỗ." , settings.EmailAdmin , settings.PasswordEmail , "CTY Global Trip"); } return(RedirectToAction("Index", "Tour")); } return(RedirectToAction("Index", "Tour")); }
public void Add(Customer customer, Product product, int quantity, Campaign campaign = null) { decimal orderTotal = decimal.Zero; Order order = new Order() { Id = 1, CustomerId = customer.Id, Customer = customer }; OrderItem orderItem = new OrderItem() { Id = 1, OrderId = order.Id, ProductId = product.Id, Product = product, Quantity = quantity }; _orderItemService.Add(orderItem); orderTotal = orderItem.Product.Price * quantity; if (campaign != null) { decimal discount = product.Price * quantity * campaign.Discount; order.Campaign = campaign; order.CampaignId = campaign.Id; order.OrderTotal = orderTotal - discount; Console.WriteLine("Add Order (Discount: " + discount + ") For Customer Id: " + customer.Id); } else { order.OrderTotal = orderTotal; Console.WriteLine("Add Order For Customer Id: " + customer.Id); } }
public Order CheckOut(Order order) { if (ApplicationContext.CurrentCustomer != null) { var baskets = Get().ToList(); if (!baskets.Any()) { return(order); } order.UserId = ApplicationContext.CurrentCustomer.UserID; order.OrderStatus = (int)OrderStatus.UnPaid; order.Total = baskets.Sum(m => m.Price * m.Quantity); _orderService.Add(order); foreach (var item in baskets) { _orderItemService.Add(item.ToOrderItem(order.ID)); } RemoveRange(baskets.ToArray()); } return(order); }
// POST: api/OrderItems public IHttpActionResult Post([FromBody] OrderItem item, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _service.Add(item, ct); } catch { if (ItemExists(item.OrderItemId)) { return(Conflict()); } throw; } return(CreatedAtRoute("OrderItemRoute", new { id = item.OrderItemId }, item)); }