Exemplo n.º 1
0
        public ActionResult UpdateStoragePlace(int id)
        {
            var model = storageRepo.GetItem(id);

            ViewBag.PlaceName = model.StoragePlaceId;
            ViewBag.ProductId = new SelectList(productRepo.GetItems(), "Id", "Name", model.ProductId);
            return(View(new StoragePlaceProductVM {
                Id = id, ProductId = (int)model.ProductId, WarehouseId = model.WarehouseId, TotalAmount = model.TotalAmount, ReservedAmount = model.ReservedAmount
            }));
        }
Exemplo n.º 2
0
 // GET: OrderProducts/Create
 public ActionResult Create()
 {
     ViewBag.OrderId   = new SelectList(orderRepo.GetItems(), "Id", "Id");
     ViewBag.ProductId = new SelectList(productRepo.GetItems(), "Id", "Name");
     return(View());
 }
Exemplo n.º 3
0
        public ActionResult UploadJson(OrderUploadVM model)
        {
            byte[] data;

            if (model.File == null)
            {
                ModelState.AddModelError("NullFile", "Inget filnamn angivet");
                return(View());
            }

            using (MemoryStream ms = new MemoryStream())
            {
                model.File.InputStream.CopyTo(ms);
                data = ms.ToArray();
            }

            var json = Encoding.Default.GetString(data);

            JObject jCustomerOrder = JObject.Parse(json);

            var items = customerAddressRepo.GetItems();

            var cid = (string)jCustomerOrder["customerid"];
            var aid = (string)jCustomerOrder["addressid"];

            var customerAddress = customerAddressRepo.GetItems().Where(
                a => a.AddressType == AddressType.Leverans &&
                a.Address.AddressOrderId == aid &&
                a.Customer.CustomerOrderId == cid).SingleOrDefault();

            if (customerAddress == null)
            {
                ModelState.AddModelError("", $"Kundorderid: '{cid}' eller Adressorderid: '{aid}' är felaktigt.");
                return(View());
            }

            var customer = customerAddress.Customer;

            var allProducts = productRepo.GetItems();

            string   dStr = (string)jCustomerOrder["date"];
            DateTime dDate;

            if (dStr.Length < 1)
            {
                dDate = DateTime.Now;
            }
            else if (!DateTime.TryParse(dStr, out dDate))
            {
                ModelState.AddModelError("", $"Önskad leveransdatum: '{dStr}' är felaktigt.");
                return(View());
            }

            var order = new Order
            {
                CustomerId          = customerAddress.Customer.Id,
                AddressId           = customerAddress.Address.Id,
                OrderDate           = DateTime.Today,
                DesiredDeliveryDate = dDate,
                Comment             = (string)jCustomerOrder["comment"]
            };

            if (customer != null)
            {
                var firstPossibleDate = DateTime.Today.AddDays(customer.DaysToDelievery);
                order.PlannedDeliveryDate = (order.DesiredDeliveryDate.CompareTo(firstPossibleDate) <= 0) ? firstPossibleDate : order.DesiredDeliveryDate;
            }

            var jProducts = jCustomerOrder["products"].ToArray();

            foreach (var jProduct in jProducts)
            {
                var prodString = (string)jProduct["pno"];
                var product    = productRepo.GetItem(prodString);
                if (product == null)
                {
                    ModelState.AddModelError("", $"Produktorderid: '{prodString}' finns inte.");
                    return(View());
                }

                var  aStr = (string)jProduct["amount"];
                uint oa;
                if (!uint.TryParse(aStr, out oa))
                {
                    ModelState.AddModelError("", $"Beställt antal: '{aStr}' är felaktigt.");
                    return(View());
                }
                if (oa < 1)
                {
                    ModelState.AddModelError("", $"Beställt antal: '{aStr}' mindre än 1.");
                    return(View());
                }
                var orderProduct = new OrderProduct
                {
                    OrderId       = order.Id,
                    Comment       = (string)jProduct["comment"],
                    ProductId     = productRepo.GetItem((string)jProduct["pno"]).Id,
                    OrderedAmount = (int)oa
                };
                order.OrderProducts.Add(orderProduct);
            }

            var existingOrders = orderRepo.GetItems().Where(o => o.AddressId == order.AddressId && o.CustomerId == order.CustomerId);

            foreach (var item in existingOrders)
            {
                if (item.DesiredDeliveryDate.Equals(order.DesiredDeliveryDate) && item.Comment.Equals(order.Comment))
                {
                    ModelState.AddModelError("", "En order med samma kundorderid, adressorderid och önskat leveransdatum är redan registrerad.");
                    return(View());
                }
            }

            orderRepo.CreateItem(order);
            //foreach (var item in order.OrderProducts)
            //{
            //    orderProductRepo.CreateItem(item);
            //}
            //orderRepo.HandleOrder(order);
            return(RedirectToAction("Index", "Orders"));
        }
Exemplo n.º 4
0
        // GET: Products
        public ActionResult Index()
        {
            var model = productRepo.GetItems();

            return(View(model));
        }
Exemplo n.º 5
0
 //GET: PriceList/Create
 public ActionResult Create()
 {
     ViewBag.ProductId       = new SelectList(productRepository.GetItems(), "Id", "Name");
     ViewBag.CustomerGroupId = new SelectList(customerGroupRepository.GetItems(), "Id", "Name");
     return(View());
 }