public IActionResult Edit(int id, string returnUrl) { var userID = Task.Run(async() => await userManager.FindByNameAsync(User.Identity.Name)).Result.Id; var rolecheck = (from role in context.UserRoles.ToList() where role.UserId == userID select role).FirstOrDefault(); if (rolecheck != null) { ViewBag.ReturnUrl = returnUrl; var productOrderDetail = productOrderDetailRepository.Get(id); var od = new OrderViewModel(); if (productOrderDetail != null) { od.Name = productRepository.Get(productOrderDetail.ProductId).Name; od.Price = productRepository.Get(productOrderDetail.ProductId).Price; od.PodId = productOrderDetail.ProductOrderDetailId; od.Count = productOrderDetail.Count; od.ProductId = productOrderDetail.ProductId; od.OrderDetailId = productOrderDetail.OrderDetailId; od.ProductOrderDetailId = id; od.OrderId = orderDetailRepository.Get(productOrderDetailRepository.Get(id).OrderDetailId).OrderId; od.Total = productRepository.Get(productOrderDetail.ProductId).Price *productOrderDetail.Count; return(View(od)); } else { return(RedirectToAction("PageNotFound", "Error")); } } else { return(RedirectToAction("AccessDenied", "Account")); } }
public void Edit(OrderDetailItem orderDetailItem) { var orderDetail = _orderDetailRepository.Get(orderDetailItem.Id); FillOrderDetail(orderDetail, orderDetailItem); _orderDetailRepository.Save(); }
public void Create(OrderDetail obj) { var detail = OrderDetailRepository.Get(obj.OrderId, obj.ProductId); if (detail != null) { throw new InsertEntityException("Entity already exist."); } OrderDetailRepository.InsertDetailsInOrder(obj.OrderId, new List <OrderDetail> { obj }); }
//public BaseViewModel<string> DeleteOrder(Guid id) //{ // //Find product // var order = _orderDetaiRrepository.GetById(id); // //result to return // BaseViewModel<string> result = null; // //check product exist // if (order == null || order.IsDelete) // { // result = new BaseViewModel<string>() // { // StatusCode = HttpStatusCode.NotFound, // Code = ErrMessageConstants.NOTFOUND, // Description = MessageHandler.CustomErrMessage(ErrMessageConstants.NOTFOUND) // }; // } // else // { // //update column isDelete = true // order.IsDelete = true; // _orderDetaiRrepository.Update(order); // result = new BaseViewModel<string>(); // //save change // Save(); // } // return result; //} public BaseViewModel <OrderWithOrderDetailViewModel> GetOrderDetail(Guid id, Expression <Func <OrderDetail, bool> > filter, string include = null) { var includeList = IncludeLinqHelper <OrderDetail> .StringToListInclude(include); var orderDetail = _orderDetaiRrepository.Get(filter, includeList).ToList(); if (orderDetail == null || orderDetail.Count == 0) { return(new BaseViewModel <OrderWithOrderDetailViewModel> { StatusCode = HttpStatusCode.NotFound, Description = MessageHandler.CustomErrMessage(ErrMessageConstants.NOTFOUND), Code = ErrMessageConstants.NOTFOUND }); } var order = _orderRepository.Get(_ => _.Id == id); return(new BaseViewModel <OrderWithOrderDetailViewModel> { Data = new OrderWithOrderDetailViewModel() { TotalPrice = order.TotalPrice ?? 0, ToTalQuantity = order.TotalQuantity ?? 0, OrderDetail = _mapper.Map <IEnumerable <OrderDetailViewModel> >(orderDetail), OrderStatus = order.Status } }); }
public ActionResult UpdateOrderDetail(UpdateOrderDertail req) { if (ModelState.IsValid) { if (_orderRepository.CheckStatusOrder(req.OrderId) == 0) { if (_orderDetailRepository.CheckOrderDetailBelongToOrder(req.OrderDetailId, req.OrderId) == 1) { Order order = _orderRepository.Get(req.OrderId); if (order.UserId.Equals(req.UserId)) { OrderDetail orderDetail = _orderDetailRepository.Get(req.OrderDetailId); if (orderDetail != null) { int price = req.UnitPrice; if (req.Mode == 1) { orderDetail.Quantity += 1; // nếu user giảm quantity thì quantity âm } else if (req.Mode == 0) { orderDetail.Quantity -= 1; price = -price; } else { return(BadRequest(JsonConvert.SerializeObject(new { message = "Mode must between 1 or 0" }))); } if (_orderDetailRepository.SaveChanges() == 1) { int result = UpdateOrderAfterBuy(req.OrderId, price); if (result != -1) { return(Ok(JsonConvert.SerializeObject(new { totalPrice = result }))); } } return(BadRequest(JsonConvert.SerializeObject(new { message = "Server Error." }))); } } return(BadRequest(JsonConvert.SerializeObject(new { message = "The order is not macth to user." }))); } return(BadRequest(JsonConvert.SerializeObject(new { message = "Order detail is not match to order." }))); } return(BadRequest(JsonConvert.SerializeObject(new { message = "The cart is done." }))); } return(BadRequest(ModelState)); }
public IActionResult Get(int id) { try { return(Ok(orderDetailRepository.Get(id))); } catch (Exception e) { throw e; } }
private OrdersConstructorViewModel GetOffalsSource(Order order) { var offalLabels = new BindingList <OrderConstructorViewModel>(); var countId = 0; foreach (var x in order.OrderDetail.Where(x => x.Product.IsOffal)) { var label = _labelService.GetLabels(x.Id).LastOrDefault(); if (label != null) { offalLabels.Add(new OrderConstructorViewModel { OrderDetailId = x.Id, ProductId = x.ProductId, ProductName = x.Product.EnglishDescription, LocationId = x.CustomerLocationId, ShipTo = x.CustomerLocation.Name, Weight = (decimal)LabelCreateService.GetGrossPoundWeight(label.PoundWeight, _activeLabelType, _orderDetailRepository.Get(x.Id)), Id = countId++ }); } } var offals = _productRepository.GetOffalProducts() .Select(x => new OrderConstructorViewModel { ProductId = x.Id, ProductName = x.Upc }) .ToList(); var locations = order.Customer .CustomerLocation .Select(x => new SelectListItemModel { Id = x.Id, Name = x.Name }) .ToList(); var model = new OrdersConstructorViewModel { ProductNameHeader = "Product Name", WeightHeader = "Box Weight", ShipToHeader = "Ship To", QtyHeader = "Qty", Orders = new BindingList <OrderConstructorViewModel>(offalLabels), Constructor = new BindingList <OrderConstructorViewModel>(offals), Locations = new BindingList <SelectListItemModel>(locations) }; return(model); }
public void UpdateLabel(int labelId, double poundWeight, OmsLabelType labelType) { Label label = _labelRepository.Get(labelId); var od = _orderDetailRepository.Get(label.OrderDetailId); label.IsPrinted = false; label.PoundWeight = LabelCreateService.GetNetPoundWeight(poundWeight, labelType, od); label.KilogramWeight = LabelCreateService.GetCorrectKilogramWeight(label.PoundWeight); label.CreatedDate = DateTime.Now; label.ProcessDate = od.Order.ProcessDate.GetValueOrDefault().ToString("d"); _labelRepository.Update(label); _labelRepository.Save(); }
//GET api/OrderDetail //[Route("api/OrderDetails")] public IEnumerable <OrderDetailIndexViewModel> GetOrderDetails() { return(Mapper.Map <IEnumerable <OrderDetailIndexViewModel> >(_orderDetailRepository.Get().ToList())); //return _orderDetailRepository.Get().ToList(); }
private LabelOutputViewModel GetLabelLayoutViewModel(int orderDetailId, OmsLabelType labelType) { var orderDetail = _orderDetailRepository.Get(orderDetailId); var order = orderDetail.Order; var product = orderDetail.Product; _customerRepository.Detach(order.Customer); var customer = order.Customer; var model = new LabelOutputViewModel(); var customerProductCode = product.CustomerProductCode.FirstOrDefault(cpc => cpc.CustomerId == orderDetail.Order.CustomerId); model.OrderDetailId = orderDetailId; model.Type = labelType; model.ItemCode = product.Upc; model.LotNumber = GetLotNumber(order); model.Description = product.Description; model.ProcessDate = order.ProcessDate ?? DateTime.Today; model.SlaughterDate = order.SlaughterDate ?? DateTime.Today; model.BestBeforeDate = order.BestBeforeDate; model.SpeciesBugPath = GetSpeciesBugPath(product); switch (customer.LogoTypeId) { case OmsLogoType.None: model.LogoPath = SettingsManager.Current.NoLogoImageFileName; break; case OmsLogoType.Customer: model.LogoPath = customer.LogoFileName ?? SettingsManager.Current.NoLogoImageFileName; break; case OmsLogoType.DoubleJ: model.LogoPath = SettingsManager.Current.DoubleJLogoFileName; break; default: throw new IndexOutOfRangeException("Order.LogoTypeId"); } model.BornInRegionName = order.BornRegion.With(x => x.Name); model.RaisedInRegionName = order.RaisedRegion.With(x => x.Name); model.ProductOfRegionName = order.ProductOfRegion.With(x => x.Name); model.DistributedBy = customer.DistributedBy; model.LabelFile = SetLabelFile(labelType, customer); model.GermanDescription = product.GermanDescription; model.FrenchDescription = product.FrenchDescription; model.ItalianDescription = product.ItalianDescription; model.SwedishDescription = product.SwedishDescription; model.Organic = GetOrganicPath(product); model.SerialNumber = GetSerialNumber(); model.VarCustomerJobValue = order.AdditionalInfoOnLabel; model.Primal = product.PrimalCut.Return(x => x.Name); model.SubPrimal = product.SubPrimalCut.Return(x => x.Name); model.PackedFor = customer.Name; model.Refrigeration = order.Refrigeration.Return(x => x.Name); model.Trim = product.TrimCut.Return(x => x.Name); model.GradeName = product.QualityGrade.Return(x => x.Name); model.CustomerProductCode = customerProductCode == null || customerProductCode.ProductCode == null ? product.Code : customerProductCode.ProductCode; model.VarCustomerProductValue = customerProductCode == null || customerProductCode.ProductDescription == null ? null : customerProductCode.ProductDescription; model.Customer = customer.Name; model.WeighedDate = DateTime.Now; return(model); }