Ejemplo n.º 1
0
        public ActionResult Create(OrderFormModel model, [DataSourceRequest] DataSourceRequest request)
        {
            Contract.Requires(model != null);

            if (this.ModelState.IsValid)
            {
                var order = this.OrderRepository.Create();

                var orderHistory = this.OrderHistoryRepository.Create();

                OrderFormModel.ToData(order, model);

                var product = this.ProductRepository.GetQueryable().FirstOrDefault(s => s.Id == model.ProductId);

                if (order.Products == null)
                {
                    order.Products = new List <Product>();
                }

                order.Products.Add(product);

                orderHistory.Amount = product.StorageCapacity;
                orderHistory.Price  = product.Price;

                this.OrderHistoryRepository.Insert(orderHistory);
                this.OrderRepository.Insert(order);

                this.UnityOfWork.Save();

                model.Id = order.Id;
            }


            return(this.JsonNet(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }
Ejemplo n.º 2
0
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, OrderFormModel model)
        {
            Contract.Requires(model != null);

            if (this.ModelState.IsValid)
            {
                var order = this.OrderRepository.GetById(model.Id);

                if (order == null)
                {
                    throw new Exception("Objednávka nenalezen.");
                }

                OrderFormModel.ToData(order, model);

                this.OrderRepository.Update(order);

                this.UnityOfWork.Save();
            }

            return(this.JsonNet(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }