public IActionResult Create(OrderRowViewModel orderRow) { if (ModelState.IsValid) { _orderRowService.Create(orderRow); return(RedirectToAction("Index")); } return(View(orderRow)); }
public IActionResult Create() { OrderRowViewModel vm = new OrderRowViewModel(); vm.Orders = _orderService.All(); vm.Products = _productService.All_Current(); return(View(vm)); }
private OrderRowViewModel BuildOrderRow(OrderRowCarrier orderRow, Currency currency, bool includeVat) { var variant = _variantService.Get(orderRow.ArticleNumber); var baseProduct = _baseProductService.Get(variant?.BaseProductSystemId ?? Guid.Empty); var name = variant?.Localizations.CurrentCulture.Name.NullIfWhiteSpace() ?? baseProduct?.Localizations.CurrentCulture.Name.NullIfWhiteSpace() ?? orderRow.ArticleNumber; var url = variant == null ? null : _urlService.GetUrl(variant); var image = (variant?.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images)?.FirstOrDefault() ?? baseProduct?.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images)?.FirstOrDefault()) .MapTo <ImageModel>(); var price = GetPriceModel(orderRow, currency, includeVat); var totalPrice = new ProductPriceModel.PriceItem(decimal.MinusOne, orderRow.TotalPrice, orderRow.VATPercentage, orderRow.TotalPriceWithVAT) { FormatPrice = b => currency.Format(includeVat ? orderRow.TotalPriceWithVAT : orderRow.TotalPrice, b, CultureInfo.CurrentUICulture) }; var unitOfMeasurement = _unitOfMeasurementService.Get(orderRow.SKUCode); var unitOfMeasurementFormatString = $"0.{new string('0', unitOfMeasurement?.DecimalDigits ?? 0)}"; var model = new OrderRowViewModel { ArticleNumber = orderRow.ArticleNumber, Name = name, RowSystemId = orderRow.ID, Quantity = orderRow.Quantity, QuantityString = orderRow.Quantity.ToString(unitOfMeasurementFormatString, CultureInfo.CurrentUICulture.NumberFormat).Replace(",", "."), Url = url, Image = image?.GetUrlToImage(Size.Empty, new Size(200, 120)).Url, TotalPrice = totalPrice.FormatPrice(true), Price = price.Price.FormatPrice(true), CampaignPrice = price.CampaignPrice?.FormatPrice(true), IsFreeGift = orderRow.IsAutoGenerated }; if (orderRow.CampaignID == Guid.Empty) { return(model); } var campaign = _moduleECommerce.Campaigns.GetCampaign(orderRow.CampaignID, _moduleECommerce.AdminToken); if (campaign == null) { return(model); } var requestModel = _requestModelAccessor.RequestModel; var channel = campaign.Data.Channels.Find(x => x.ChannelId == requestModel.ChannelModel.SystemId); if (channel != null && channel.CampainPage != null && channel.CampainPage.EntitySystemId != Guid.Empty) { model.CampaignLink = channel.CampainPage.MapTo <LinkModel>()?.Href; } return(model); }
public OrderRow Create(OrderRowViewModel orderRow) { OrderRow newOrderRow = new OrderRow() { OrderId = orderRow.OrderId, ProductId = orderRow.ProductId, /*the choosen product*/ Price = orderRow.Price, GlutenFree = orderRow.GlutenFree }; return(_orderRowRepo.Create(newOrderRow)); }
public IActionResult CreateOrderRow(int orderId) { try { OrderRowViewModel orderRow = new OrderRowViewModel(); orderRow.OrderId = orderId; return(View(orderRow)); } catch (Exception ex) { return(View("Error", ex.Message)); } }
public IActionResult CreateOrderRow(OrderRowViewModel orderRow) { try { Article articleToCreate = new Article(); int articleId = 0; articleToCreate = articleToCreate.GetIfArticleByNameExist(orderRow.ArticleName); //Article exist in database if (articleToCreate != null) { articleId = articleToCreate.Id; //Overides users choosen article number since the item exists in the db. orderRow.ArticleNumber = articleToCreate.ArticleNumber; } //Create new Article if (articleToCreate is null) { articleToCreate = new Article() { ArticleName = orderRow.ArticleName, Price = orderRow.Price, ArticleNumber = orderRow.ArticleNumber }; articleId = articleToCreate.CreateArticle(articleToCreate); } OrderRow orderRowToCreate = new OrderRow() { ArticleId = articleId, OrderId = orderRow.OrderId, RowNumber = OrderHelper.GetOrderRowNumber(orderRow.OrderId), ArticleAmount = orderRow.ArticleAmount, }; int orderRowId = orderRowToCreate.CreateOrderRow(orderRowToCreate); return(RedirectToAction("Details", new { id = orderRow.OrderId })); } catch (Exception ex) { return(View("Error", ex.Message)); } }
public IHttpActionResult Update(OrderRowViewModel model) { if (model.Quantity >= 0) { Cart.UpdateRowQuantity(model.RowSystemId, model.Quantity); Cart.UpdateChangedRows(); if (model.Quantity <= 0 && !string.IsNullOrEmpty(Cart.OrderCarrier.CampaignInfo) && ClearCampaignCode()) { // Campaign code must be cleared if order doesn't have applied voucher code. Cart.OrderCarrier.CampaignInfo = string.Empty; Cart.UpdateChangedRows(); } } return(Ok(_cartViewModelBuilder.Build(Cart))); }
public async Task <IEnumerable <OrderViewModel> > GetCancellations(UserProfile user, DateTime from, DateTime to, int shopId) { IEnumerable <Shop> shops = new List <Shop>(); var orders = new List <OrderViewModel>(); var ordersDal = new List <Order>(); var avl = shopsChecker.CheckAvailability(user, shopId); if (!avl.isCorrectShop) { return(new List <OrderViewModel>()); } if (!avl.hasShop && avl.isAdmin) { shops = shopRepo.GetShopsByBusiness(user.business_id.Value); } else if (!avl.hasShop && !avl.isAdmin) { return(new List <OrderViewModel>()); } else if (avl.hasShop) { shops = new List <Shop> { shopRepo.GetById(shopId) }; } if (shops == null || !shops.Any()) { return(new List <OrderViewModel>()); } foreach (var shop in shops) { ordersDal.AddRange(await ordersRepo.GetCancellationsByShopIdInDateRange(shop.id, from, to)); } var orderGroups = ordersDal.OrderByDescending(p => p.report_date); foreach (var group in orderGroups) { var orderVm = new OrderViewModel { id = group.id, reportDate = group.report_date }; foreach (var item in group.OrderDetails) { var prodDal = await productRepo.GetByIdAsync(item.prod_id); var cost = costRepo.GetByProdAndShopIds(item.prod_id, shopId); var prod = new OrderRowViewModel { image = (await imgRepo.GetByIdAsync(item.prod_id))?.img_url_temp, name = prodDal.name, price = cost.value, count = item.count, totalPrice = item.count * cost.value, vendorCode = prodDal.attr1 }; prod.totalPrice = prod.price * prod.count; orderVm.products.Add(prod); } orders.Add(orderVm); } return(orders); }