コード例 #1
0
 public OrderViewModel(Order order)
 {
     Product = order.Product;
     Price = order.Price;
     DeliveryDate = order.DeliveryDate;
     IsReady = order.IsReady;
     User = order.User;
     ProductCode = order.ProductCode;
 }
コード例 #2
0
        public void Delete(Order order)
        {
            var orderToDelete = Get(order.Id);

            if (orderToDelete != null)
            {
                _context.Orders.Remove(orderToDelete);
                _context.SaveChanges();
            }
        }
コード例 #3
0
        public void Update(Order order)
        {
            var orderToUpdate = Get(order.Id);

            if (orderToUpdate != null)
            {
                orderToUpdate = order;
                _context.SaveChanges();
            }
        }
コード例 #4
0
 public bool UpdateOrder(Order order)
 {
     var exisitingOrder = GetOrderById(order.Id);
     if(exisitingOrder != null)
     {
         exisitingOrder = order;
         _context.SaveChanges();
         return true;
     }
     return false;
 }
コード例 #5
0
 public bool DeleteOrder(Order order)
 {
     var exisitingOrder = GetOrderById(order.Id);
     if(exisitingOrder != null)
     {
         _context.Orders.Remove(exisitingOrder);
         _context.SaveChanges();
         return true;
     }
     return false;
 }
コード例 #6
0
        public void AssertThatAddOrderReturnsAddedOrder()
        {
            var order = new Order() { Id = 103, Price = 343, IsReady = false, DeliveryDate = DateTime.Now.AddDays(10), Product = new Product() { Id = 1 } };

            Assert.AreSame(order, _service.AddOrder(order));
        }
コード例 #7
0
 public bool UpdateOrder(Order order)
 {
     return _repository.UpdateOrder(order);
 }
コード例 #8
0
 public bool DeleteOrder(Order order)
 {
     return _repository.DeleteOrder(order);
 }
コード例 #9
0
 public Order AddOrder(Order order)
 {
     return _repository.AddOrder(order);
 }
コード例 #10
0
ファイル: OrderService.cs プロジェクト: Lihte/MVCConfigurator
 public void UpdateOrder(Order order)
 {
     _repository.Update(order);
 }
コード例 #11
0
ファイル: OrderService.cs プロジェクト: Lihte/MVCConfigurator
 public void DeleteOrder(Order order)
 {
     _repository.Delete(order);
 }
コード例 #12
0
 public Order Add(Order order)
 {
     _context.Orders.Add(order);
     _context.SaveChanges();
     return order;
 }
コード例 #13
0
        public ActionResult SelectParts(CustomizeProductViewModel viewModel)
        {
            var selectedPartList = viewModel.Product.Parts.Where(p => p.IsSelected == true).ToList();

            if(selectedPartList!=null)
            {
                var deliveryDate = DateTime.Now.AddDays(selectedPartList.OrderByDescending(d => d.LeadTime).First().LeadTime);

                int productId = viewModel.Product.Id;
                StringBuilder productCode = new StringBuilder();
                decimal productPrice = 0;
                bool isReady = false;
                var userID = _userService.Get(HttpContext.User.Identity.Name).Entity;

                foreach(var part in selectedPartList)
                {
                    productPrice += part.Price;
                    isReady = deliveryDate > DateTime.Now ? false : true;
                    productCode.Append(part.StockKeepingUnit.Substring(0,2));
                }

                var order = new Order {
                    Product = _productService.GetProduct(viewModel.Product.Id),
                    DeliveryDate = deliveryDate,
                    IsReady = isReady,
                    Price = productPrice,
                    ProductId = productId,
                    User = userID };

                _orderService.AddOrder(order);

            }

            return View("~/Views/User/SelectParts.cshtml");
        }
コード例 #14
0
        public ActionResult SelectParts(CustomizeProductViewModel viewModel)
        {
            var selectedPartList = viewModel.Product.Parts.Where(p => p.IsSelected == true).ToList();

            var totalCat = viewModel.Product.Parts.Select(p => p.CategoryId).Distinct().ToArray();

            // Setup so that one part of every category must be selected before completion
            if (selectedPartList.Count() != totalCat.Count())
            {
                return View(viewModel);
            }

            var partList = new List<Part>();

            foreach (var item in selectedPartList)
            {
                partList.Add(_productService.GetProduct(viewModel.Product.Id).Parts.SingleOrDefault(p => p.Id == item.Id));
            }

            if (partList != null || partList.Count > 0)
            {
                double orderLeadtime = new double();

                foreach (var item in partList)
                {
                    orderLeadtime += item.LeadTime;
                }

                StringBuilder productCode = new StringBuilder();

                var order = new Order()
                {
                    Product = _productService.GetProduct(viewModel.Product.Id),
                    DeliveryDate = DateTime.Now.AddDays(orderLeadtime),
                    IsReady = false,
                    User = _userService.Get(HttpContext.User.Identity.Name).Entity
                };

                foreach (var part in partList)
                {
                    order.Price += part.Price;
                    order.IsReady = order.DeliveryDate > DateTime.Now ? false : true;
                    productCode.Append(part.StockKeepingUnit);
                }

                order.ProductCode = productCode.ToString();

                _orderService.AddOrder(order);
            }

            return RedirectToAction("OrderList");
        }