public IActionResult Add(OrderDetail item) { if (ModelState.IsValid) { bool result = _repository.Add(item); if (result == true) { _repository.Save(); _logger.LogInformation("OrderDetail added " + item.ID + " " + DateTime.Now.ToString()); return(RedirectToAction("List")); } else { _logger.LogError("Order Detail add failed" + " " + DateTime.Now.ToString()); return(View(item)); } } else { _logger.LogCritical("Order Detail add failed" + " " + DateTime.Now.ToString()); return(View(item)); } }
public bool Create(Order order, List <OrderDetail> orderDetails) { try { _orderRepository.Add(order); _unitOfWork.Commit(); foreach (var orderDetail in orderDetails) { orderDetail.OrderID = order.ID; _orderDetailRepository.Add(orderDetail); } _unitOfWork.Commit(); return(true); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors: "); foreach (var ve in eve.ValidationErrors) { Trace.WriteLine($" - Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""); } } throw; } catch (Exception ex) { var errorMessage = ex.Message; throw; } }
public Order Add(ref Order order, List <OrderDetail> orderDetails) { try { _orderRepository.Add(order); _unitOfWork.Commit(); foreach (var orderDetail in orderDetails) { orderDetail.OrderID = order.ID; _orderDetailRepository.Add(orderDetail); } return(order); } 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; } }
public int CreateOrder(Order order) { decimal orderTotal = 0; var cartItems = GetCartItems(); // Iterate over the items in the cart, // adding the order details for each foreach (var item in cartItems) { var orderDetail = new OrderDetail { AlbumId = item.AlbumId, OrderId = order.OrderId, UnitPrice = item.Album.Price, Quantity = item.Count }; // Set the order total of the shopping cart orderTotal += (item.Count * item.Album.Price); _orderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count order.Total = orderTotal; // Save the order _unitOfWork.SaveChanges(); // Empty the shopping cart EmptyCart(); // Return the OrderId as the confirmation number return(order.OrderId); }
public IActionResult Add(OrderDetail item) { if (ModelState.IsValid) { bool result = _repository.Add(item); if (result == true) { _repository.Save(); _logger.LogInformation("Order Detail added " + item.ID + " " + DateTime.Now.ToString()); return(RedirectToAction("List")); } else { TempData["Message"] = $"Kayıt işlemi sırasında bir hata oluştu. Lütfen tüm alanları kontrol edip tekrar deneyin..!"; _logger.LogError("Order Detail add failed" + " " + DateTime.Now.ToString()); return(View(item)); } } else { TempData["Message"] = $"Kayıt işlemi sırasında bir hata oluştu. Lütfen tüm alanları kontrol edip tekrar deneyin..!"; _logger.LogCritical("Order Detail add failed" + " " + DateTime.Now.ToString()); return(View(item)); } }
public IActionResult Post([FromBody] OrderDetailDto[] model) { try { var ordersDetails = new List <OrderDetail>(); foreach (var item in model) { var product = productRepository.Get(item.ProductId); ordersDetails.Add(new OrderDetail() { OrderId = item.OrderId, ProductId = item.ProductId, Quantity = item.Quantity }); productRepository.Update(item.ProductId, new Product() { Id = item.ProductId, Stock = product.Stock - item.Quantity }); } return(Ok(orderDetailRepository.Add(ordersDetails.ToArray()))); } catch (Exception e) { throw e; } }
public void CreateOrder(Order order) { decimal orderTotal = 0; var cartItems = GetCartItems(); foreach (var cartItem in cartItems) { var orderDetail = new OrderDetail { OrderId = order.Id, ProductId = cartItem.ProductId, UnitPrice = cartItem.Product.UnitPrice, Quantity = cartItem.Quantity }; orderTotal += cartItem.Quantity * cartItem.Product.UnitPrice; _orderDetailRepository.Add(orderDetail); } order.TotalAmount = orderTotal; EmptyCart(); }
public ActionResult Order(string customerOrder, string orderDetail) { var order = new JavaScriptSerializer().Deserialize <tbl_Order>(customerOrder); var details = new JavaScriptSerializer().Deserialize <List <OrderDetail> >(orderDetail); try { order.Status = 1; order.CreatedDate = DateTime.Now; int id = orderRepository.Add(order); foreach (var item in details) { item.OrderID = id; orderDetailRepository.Add(item); } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } }
public IActionResult Create() { var identity = (ClaimsIdentity)this.User.Identity; var claim = identity.FindFirst(ClaimTypes.NameIdentifier); CartViewModel.ShoppingCart = _shoppingCart.ListWithUser(claim.Value); CartViewModel.Order.ApplicationUserId = claim.Value; CartViewModel.Order.CreatedAt = DateTime.Now; CartViewModel.Order.UpdatedAt = DateTime.Now; CartViewModel.Order.Status = "Pending"; Order order = CartViewModel.Order; _order.Create(order); foreach (var item in CartViewModel.ShoppingCart) { item.Product = _product.Find(item.ProductId); OrderDetail orderDetail = new OrderDetail() { ProductId = item.ProductId, OrderId = order.Id, Price = item.Product.Price, Count = item.Count }; _orderDetail.Add(orderDetail); } _shoppingCart.RemoveCart(CartViewModel.ShoppingCart); _shoppingCart.Save(); HttpContext.Session.SetInt32("Counter", 0); return(RedirectToAction(nameof(Show), new { id = order.Id })); }
public BaseViewModel <IEnumerable <OrderDetailViewModel> > CreateDetail(IEnumerable <CreateOrderDetailViewModel> details) { var entities = _mapper.Map <IEnumerable <OrderDetail> >(details); foreach (var entity in entities) { entity.Id = Guid.NewGuid(); entity.SetDefaultInsertValue(_orderDetaiRrepository.GetUsername()); _orderDetaiRrepository.Add(entity); } var result = new BaseViewModel <IEnumerable <OrderDetailViewModel> >() { Data = _mapper.Map <IEnumerable <OrderDetailViewModel> >(entities), }; Save(); return(result); }
public Order Create(Order order) { try { _orderRepository.Add(order); _unitOfWork.Commit(); foreach (var orderDetail in order.OrderDetails) { orderDetail.OrderID = order.ID; _orderDetailRepository.Add(orderDetail); } _unitOfWork.Commit(); return(order); } catch (Exception ex) { throw; } }
public int Add(OrderDetailItem orderDetailItem) { var orderDetail = new OrderDetail { OrderId = orderDetailItem.OrderId }; FillOrderDetail(orderDetail, orderDetailItem); _orderDetailRepository.Add(orderDetail); _orderDetailRepository.Save(); return(orderDetail.Id); }
public void Update(OrderViewModel orderVm) { //Mapping to order domain var order = _mapper.Map <OrderViewModel, Order>(orderVm); //Get order Detail var newDetails = order.OrderDetails; //new details added var addedDetails = newDetails.Where(x => x.Id == 0).ToList(); //get updated details var updatedDetails = newDetails.Where(x => x.Id != 0).ToList(); //Existed details var existedDetails = _orderDetailRepository.FindAll(x => x.OrderId == orderVm.Id); //Clear db order.OrderDetails.Clear(); foreach (var detail in updatedDetails) { var product = _productRepository.FindById(detail.ProductId); detail.Price = product.Price; _orderDetailRepository.Update(detail); } foreach (var detail in addedDetails) { var product = _productRepository.FindById(detail.ProductId); detail.Price = product.Price; _orderDetailRepository.Add(detail); } _orderDetailRepository.RemoveMultiple(existedDetails.Except(updatedDetails).ToList()); _orderRepository.Update(order); }
// POST api/OrderDetail public HttpResponseMessage PostOrderDetail(Order_Detail orderDetail) { if (ModelState.IsValid) { _orderDetailRepository.Add(orderDetail); _unitOfWork.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, orderDetail); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { OrderId = orderDetail.OrderID, productId = orderDetail.ProductID })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public bool Create(Order oder, List <OrderDetail> orderDetails) { try { var order = _orderRepository.Add(oder); _unitOfWork.Commit(); foreach (var orderDetail in orderDetails) { orderDetail.OrderID = order.ID; _orderDetailRepository.Add(orderDetail); } _unitOfWork.Commit(); return(true); } catch (Exception ex) { throw; } }
public bool Create(Order order, List <OrderDetail> orderDetail) { try { order.CreatedDate = DateTime.Now; _orderRepository.Add(order); foreach (var itemDetail in orderDetail) { itemDetail.OrderId = order.Id; _orderDetailRepository.Add(itemDetail); } return(true); } catch { return(false); } }
public bool CreateOrder(Order order, List <OrderDetail> orderDetail) { try { _orderRepository.Add(order); _unitOfWork.Commit(); foreach (var orderDetailItem in orderDetail) { orderDetailItem.OderID = order.ID; _orderDetailRepository.Add(orderDetailItem); } _unitOfWork.Commit(); return(true); } catch (Exception) { return(false); } }
public Order Create(ref Order order, List <OrderDetail> orderDetails) { try { _orderRepository.Add(order); _unitOfWork.Commit(); foreach (var orderDetail in orderDetails) { orderDetail.OrderID = order.ID; _orderDetailRepository.Add(orderDetail); } return(order); } catch { throw; } }
public async Task <IActionResult> SummaryPost(ProductUserVM ProductUserVM) { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); //we need to create an order OrderHeader orderHeader = new OrderHeader() { ApplicationUserId = claim.Value, FinalOrderTotal = ProductUserVM.ProductList.Sum(x => x.TempQty * x.Price), City = ProductUserVM.ApplicationUser.City, StreetAddress = ProductUserVM.ApplicationUser.StreetAddress, PostalCode = ProductUserVM.ApplicationUser.PostalCode, FullName = ProductUserVM.ApplicationUser.FullName, Email = ProductUserVM.ApplicationUser.Email, PhoneNumber = ProductUserVM.ApplicationUser.PhoneNumber, OrderDate = DateTime.Now, OrderStatus = WC.StatusPending }; _orderHRepo.Add(orderHeader); _orderHRepo.Save(); foreach (var prod in ProductUserVM.ProductList) { OrderDetail orderDetail = new OrderDetail() { OrderHeaderId = orderHeader.Id, PricePerUnit = prod.Price, Qty = prod.TempQty, ProductId = prod.Id }; var prodPopularity = _prodRepo.FirstOrDefault(u => u.Id == prod.Id); prodPopularity.ProductPopularity++; _prodRepo.Update(prodPopularity); _orderDRepo.Add(orderDetail); } _orderDRepo.Save(); TempData[WC.Success] = "Order is placed successfully"; return(RedirectToAction(nameof(OrderConfirmation), new { id = orderHeader.Id })); }
public ActionResult Order(GiveOrderDTO giveOrderDto) { if (Session["user"] != null) { try { User user = (User)Session["user"]; Order order = new Order { CustomerID = user.UserID, Notes = giveOrderDto.Notes, Address = Mapper.Map <Address>(giveOrderDto.ShippingAddress), ShippingTypeID = giveOrderDto.ShippingTypeID }; orderRepository.Add(order); orderRepository.Save(); Cart cart = cartRepository.GetById(giveOrderDto.CartID); foreach (var cartDetail in cart.CartDetails) { OrderDetail orderDetail = new OrderDetail { ProductDetailID = cartDetail.ProductDetailID, OrderID = order.OrderID, Quantity = cartDetail.Quantity, Discount = cartDetail.Discount, UnitPrice = cartDetail.UnitPrice }; orderDetailRepository.Add(orderDetail); orderDetailRepository.Save(); } cartRepository.Delete(cart); cartRepository.Save(); } catch (Exception e) { return(RedirectToAction("Index")); } } return(Redirect("/")); }
public ActionResult Add(OrderDetailRequest req) // ok { if (ModelState.IsValid) { if (_orderRepository.CheckStatusOrder(req.OrderId) == 0) { OrderDetail o = _orderDetailRepository.GetOrderDetailFollowOption(req.OrderId, req.ProductId, req.Size); if (o != null) { o.Quantity += req.Quantity; } else { OrderDetail orderDetail = new OrderDetail() { OrderId = req.OrderId, ProductId = req.ProductId, ProductName = req.ProductName, Quantity = req.Quantity, UnitPrice = req.UnitPrice, Size = req.Size }; _orderDetailRepository.Add(orderDetail); } if (_orderDetailRepository.SaveChanges() > 0) { int totalPrice = req.Quantity * req.UnitPrice; int result = UpdateOrderAfterBuy(req.OrderId, totalPrice); if (result != -1) { return(Ok(JsonConvert.SerializeObject(new { totalPrice }))); } return(BadRequest(JsonConvert.SerializeObject(new { Error = "Update total price in order fail." }))); } } return(BadRequest(JsonConvert.SerializeObject(new { Error = "Add fail." }))); } return(BadRequest(ModelState)); }
public JsonResult CreateOrderDetail(int id, OrderDetailViewModel orderDetailViewModel, [DataSourceRequest] DataSourceRequest dataSourceRequest) { var order = _orderRepository.GetAllOrders().SingleOrDefault(o => o.OrderId == id); if (order.OrderDate > orderDetailViewModel.ValueDate) { ModelState.AddModelError("OrderDate", "Order detail can't pre-date order"); } if (ModelState.IsValid) { orderDetailViewModel.OrderId = id; var orderDetail = Mapper.Map <OrderDetail>(orderDetailViewModel); _orderDetailRepository.Add(orderDetail); _orderDetailRepository.SaveChanges(); orderDetailViewModel.OrderDetailId = orderDetail.OrderDetailId; } var resultData = new[] { orderDetailViewModel }; return(Json(resultData.AsQueryable().ToDataSourceResult(dataSourceRequest, ModelState))); }
public Order Create(ref Order order, List <OrderDetail> orderDetails) { try { // add order(chứa thông tin người mua hàng) vào db _orderRepository.Add(order); _unitOfWork.Commit(); // add orderDetail(chứ số lượng sp,sp) vào db foreach (var orderDetail in orderDetails) { orderDetail.OrderID = order.ID; _orderDetailRepository.Add(orderDetail); } return(order); } catch (Exception) { throw; } }
public ActionResult checkout(Order Order, short?restaurantId, List <Order_detail> Order_details) { if (ModelState.IsValid) { Order.order_created_date = DateTime.Now; _orderRepository.Add(Order); var restaurantOrder = new User_order() { user_id = (short)restaurantId, user_order_created_date = DateTime.Now, user_order_pay = 1, order_id = Order.order_id }; _userOrderRepository.Add(restaurantOrder); var customerOrder = new User_order() { user_id = (short)Convert.ToInt32(Session["userId"]), user_order_created_date = DateTime.Now, user_order_pay = 2, order_id = Order.order_id }; _userOrderRepository.Add(customerOrder); foreach (var item in Order_details) { item.Order_detail_order_id = Order.order_id; _orderDetailRepository.Add(item); var food = _foodRepository.GetById(item.Order_detail_food_id); food.food_served += item.Order_detail_quantity; food.food_quantity -= item.Order_detail_quantity; _foodRepository.Update(food); } return(RedirectToAction("Details", "Users", new { id = Session["userId"] })); } return(Content("<script language='javascript' type='text/javascript'>alert('Something wrong wrong!');</script>")); }
public void Add(OrderDetail orderDetail) { _orderDetailRepository.Add(orderDetail); }
private void CreateOrderDetail(OrderDetail detail) { _orderDetailRepository.Add(detail); _unitOfWork.Commit(); }
public OrderDetail Add(OrderDetail orderDetail) { return(_orderDetailRepository.Add(orderDetail)); }
public OrderDetail Add(OrderDetail entity) { return(_OrderDetailRepository.Add(entity)); }
public void AddOrderDetail(OrderDetail orderdetail) { _OrderDetailRepository.Add(orderdetail); _unitofwork.Save(); }
public OrderDetail CreateDetail(OrderDetail order) { return(_orderDetailRepository.Add(order)); }