コード例 #1
0
        public async Task <IActionResult> AddOrderItem(IEnumerable <string> productIds)
        {
            var itemToAdd          = (await _orderRepository.GetProducts()).FirstOrDefault(product => productIds.All(id => id != product.Id));
            var orderLineViewmodel = new OrderLineViewModel {
                ProductImage = itemToAdd.Image, ProductId = itemToAdd.Id, ProductPrice = itemToAdd.Price, Quantity = 1
            };

            return(PartialView("EditorTemplates/OrderLineViewModel", orderLineViewmodel));
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: Raakost/MusicShop
        public void orderline_properties_set_test()
        {
            OrderLineViewModel line = new OrderLineViewModel();
            var movie = new Movie() { Id = 1, Title = "The Ring", Price = 200 };
            line.Movie = movie;
            line.Amount = 10;

            Assert.AreEqual(line.Movie, movie, "Movies are the same");
            Assert.AreEqual(line.Amount, 10, "Movie amount is wrong");
        }
コード例 #3
0
 public ActionResult ConfirmAddToCart(OrderLineViewModel viewModel)
 {
     if (_businessLogic.CurrentUserIsCustomer())
     {
         viewModel.OrderLineId = Guid.NewGuid();
         viewModel.TotalPrice  = viewModel.Quantity * viewModel.Price;
         _businessLogic.AddToCart(viewModel);
         //add to cart
     }
     return(RedirectToAction("Index", "Home"));
 }
コード例 #4
0
        /// <summary>
        /// returns an order viewmodel based on a given inventory viewmodel that it is being created from
        /// </summary>
        /// <param name="inventoryViewModel"></param>
        /// <returns></returns>
        public OrderLineViewModel CreateOrderLine(InventoryViewModel inventoryViewModel)
        {
            OrderLineViewModel viewModel = new OrderLineViewModel()
            {
                InventoryId = inventoryViewModel.InventoryId,
                Price       = inventoryViewModel.Price,
                ProductName = inventoryViewModel.ProductName,
                Quantity    = 0,
                StoreName   = inventoryViewModel.LocationName,
                TotalPrice  = 0,
            };

            return(viewModel);
        }
コード例 #5
0
        public void orderline_properties_set_test()
        {
            OrderLineViewModel line = new OrderLineViewModel();
            var movie = new Movie()
            {
                Id = 1, Title = "The Ring", Price = 200
            };

            line.Movie  = movie;
            line.Amount = 10;

            Assert.AreEqual(line.Movie, movie, "Movies are the same");
            Assert.AreEqual(line.Amount, 10, "Movie amount is wrong");
        }
コード例 #6
0
ファイル: OrderFood.xaml.cs プロジェクト: alihan21/FlightApp
        private void RemoveFromOrder(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Button test         = (Button)e.OriginalSource;
            Food   selectedFood = (Food)test.DataContext;

            OrderLineViewModel existingOrderLine = GetExistingOrderLineByFoodId(selectedFood);

            if (existingOrderLine != null)
            {
                OrderViewModel.Total -= Math.Round(selectedFood.Price, 1);
                existingOrderLine.Quantity--;

                if (existingOrderLine.Quantity <= 0)
                {
                    OrderViewModel.OrderLines.Remove(existingOrderLine);
                }
            }
        }
コード例 #7
0
        public IActionResult GetProducts(int id, [Bind("ProductId", "Amount")] OrderLineViewModel viewModel)
        {
            var model = _locationRepo.GetById(id);

            model.Inventory = _locationRepo.GetAllProducts(model.Id);
            if (ModelState.IsValid)
            {
                double Total = 0;
                foreach (var product in model.Inventory.Keys)
                {
                    if (TempData[product.Name] == null)
                    {
                        TempData[product.Name] = 0;
                    }

                    int count = (int)TempData[product.Name];
                    if (product.ProductId == viewModel.ProductId)
                    {
                        count += viewModel.Amount;
                        if (count > model.Inventory[product])
                        {
                            ModelState.AddModelError("", "Not enough stock available for request");
                        }
                        else
                        {
                            TempData[product.Name] = count;
                        }
                    }
                    TempData.Keep(product.Name);

                    Total += product.Price * (int)TempData[product.Name];
                }
                ViewData["Total"] = Total;

                return(View(model));
            }
            else
            {
                ModelState.AddModelError("", "Invalid quantity.");
                return(View(model));
            }
        }
コード例 #8
0
        public OrderLineViewModel GetOrderLineInfoByOrderlineId(int orderlineId, string orderCurrency)
        {
            try
            {
                // call stored procedure via repository
                var result = orderLineRepository.SQLQuery <OrderLineViewModel>("SP_GetOrderlineInfoById @orderlineId, @orderCurrency",
                                                                               new SqlParameter("orderlineId", SqlDbType.Int)
                {
                    Value = orderlineId
                },
                                                                               new SqlParameter("orderCurrency", SqlDbType.VarChar)
                {
                    Value = orderCurrency
                });

                // convert the result to orderline
                OrderLineViewModel olVm = result.FirstOrDefault <OrderLineViewModel>();
                return(olVm);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #9
0
        public void order_orderlineslist_contains_orderlines()
        {
            TestControllerBuilder builder = new TestControllerBuilder();
            //Arrange
            var bll = new OrderController(new OrderBLL(new OrderDALStub()));

            builder.InitializeController(bll);
            builder.HttpContext.Session["loggedInUser"] = new Customer()
            {
                admin = true
            };
            List <OrderLineViewModel> expected = new List <OrderLineViewModel>();
            var o = new OrderLineViewModel()
            {
                id           = 1,
                productid    = 100001.ToString(),
                quantity     = 3,
                customerid   = 1,
                orderdate    = DateTime.Now,
                orderId      = 298423,
                orderlineSum = 300,
                price        = 50.ToString(),
                productname  = "hei"
            };

            expected.Add(o);
            expected.Add(o);
            expected.Add(o);
            // Act
            var actual = (ViewResult)bll.ListOrderLines(298423, null, 2, null);
            var result = (PagedList <OrderLineViewModel>)actual.Model;

            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(result[0].orderlineSum, (int.Parse(result[0].price) * result[0].quantity));
        }
コード例 #10
0
ファイル: OrderFood.xaml.cs プロジェクト: alihan21/FlightApp
        private void AddToOrder(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Button test         = (Button)e.OriginalSource;
            Food   selectedFood = (Food)test.DataContext;

            if (selectedFood != null)
            {
                OrderLineViewModel existingOrderLine = GetExistingOrderLineByFoodId(selectedFood);

                if (existingOrderLine == null)
                {
                    OrderLineViewModel newOrderLine = new OrderLineViewModel();
                    newOrderLine.Food     = selectedFood;
                    newOrderLine.Quantity = 1;
                    OrderViewModel.OrderLines.Add(newOrderLine);
                }
                else
                {
                    existingOrderLine.Quantity++;
                }

                OrderViewModel.Total += Math.Round(selectedFood.Price, 1);
            }
        }
コード例 #11
0
        public OrderLine ConvertOrderLineViewModelToOrderLine(OrderLineViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(null);
            }
            OrderLine line = new OrderLine()
            {
                Quantity    = viewModel.Quantity,
                OrderLineId = viewModel.OrderLineId
            };
            Inventory inv = _repository.GetInventoryById(viewModel.InventoryId);
            Order     ord = _repository.GetOrderById(viewModel.OrderId);

            if (inv != null)
            {
                line.Inventory = inv;
            }
            if (ord != null)
            {
                line.Order = ord;
            }
            return(line);
        }
コード例 #12
0
        private async Task <OrderViewModel> GetOrderViewModel(Guid orderId)
        {
            OrderViewModel vm = null;

            try
            {
                var order = await _context.Orders.SingleOrDefaultAsync(m => m.ID == orderId);

                var olines = await _context.OrderLines.Where(ol => ol.OrderID.Equals(order.ID)).ToListAsync();

                List <OrderLineViewModel> lineViewModels = new List <OrderLineViewModel>();
                foreach (var item in olines)
                {
                    Product product = null;

                    product = await _context.Products.SingleAsync(p => p.ProductID == item.ProductID);

                    var mainImage = await _context.ProductImages.SingleAsync(i => i.IsMainImage && i.ProductID.Equals(item.ProductID));

                    var unit = await _context.Units.SingleAsync(u => u.UnitID == item.UnitID);

                    OrderLineViewModel lineViewModel = new OrderLineViewModel {
                        ID             = item.OrderLineID,
                        Image          = mainImage.ImageUrl,
                        OrderPrice     = item.SellBasePrice,
                        OrderQuantity  = item.Quantity,
                        ProductName    = product.Name,
                        OrderUnit      = unit.Name,
                        OrderLineTotal =
                            item.Quantity * item.SellBasePrice,
                        Position      = item.Position,
                        ProductNumber = product.ProductNumber
                    };

                    lineViewModels.Add(lineViewModel);
                }


                var shippingPrice = await _context.ShippingPrices.SingleAsync(sp => sp.ID == order.ShippingPriceId);

                var shippingPeriod = await _context.ShpippingPeriods.SingleAsync(p => p.ShippingPeriodID == order.ShippingPeriodId);

                var paymend = await _context.Paymends.SingleAsync(p => p.ID == order.PaymentID);

                var customer = await _context.Customers.SingleAsync(c => c.CustomerID.Equals(order.CustomerID));

                var user = await _context.Users.SingleAsync(u => u.Id.Equals(customer.UserId));

                var shippingAddress = await _context.ShippingAddresses.FirstOrDefaultAsync(s => s.ID == order.ShippingAddressId);

                var invoiceaddress = await _context.ShippingAddresses.FirstOrDefaultAsync(c => c.CustomerID == order.CustomerID && c.IsInvoiceAddress);

                ShippingAddressViewModel shipToAddress = null;

                if (shippingAddress != null)
                {
                    shipToAddress = addressHelper.GetViewModel(shippingAddress);
                }

                ShippingAddressViewModel invoiceVm = null;

                if (invoiceaddress == null)
                {
                    invoiceVm = addressHelper.GetViewModel(customer);
                }
                else
                {
                    invoiceVm = addressHelper.GetViewModel(invoiceaddress);
                }

                vm = new OrderViewModel {
                    ID    = order.ID,
                    EMail = user.UserName,
                    ExceptLawConditions = order.ExceptLawConditions,
                    IsClosed            = order.IsClosed,
                    IsPayed             = order.IsPayed,
                    IsSend               = order.IsSend,
                    Number               = order.Number,
                    OrderDate            = order.OrderDate,
                    FreeText             = order.FreeText,
                    Payment              = paymend.Name,
                    Shippingdate         = order.Shippingdate,
                    ShippingPriceAtOrder = order.ShippingPrice,
                    ShippingPriceName    = shippingPrice.Name,
                    ShippToAddress       = shipToAddress,
                    InvoiceAddress       = invoiceVm,
                    ShippingPeriodString = shippingPeriod.Decription,
                    Total             = order.Total,
                    CustomerFirstName = customer.FirstName,
                    CutomerLastName   = customer.Name,
                    OderLines         = lineViewModels
                };
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Admin.OrdersController.GetViewModel -> error on sql transaction", null);
            }

            return(vm);
        }
コード例 #13
0
 public static string FormatDescriptionLine(PersonEx person, WebShoppingCartDetails line, OrderLineViewModel item)
 {
     //person id 2 is guest
     return(string.Format("Registration for {0} {1}.", person.FirstName, person.LastName));
 }