public void Add(Product product)
        {
            CurrentUser = UserManager.FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
            OrderProduct orderProduct = _orderProductRepository.GetEntities()
                                        .Where(p => p.UserId == this.CurrentUser.Id && p.ProductId == product.ProductId)
                                        .FirstOrDefault();

            try
            {
                orderProduct.Quantity += 1;
                _orderProductRepository.Update(orderProduct);
                _orderProductRepository.Save();
            }
            catch (NullReferenceException e)
            {
                orderProduct = new OrderProduct()
                {
                    UserId    = CurrentUser.Id,
                    ProductId = product.ProductId,
                    Quantity  = 1
                };
                _orderProductRepository.Insert(orderProduct);
                _orderProductRepository.Save();
            }
        }
        public void Add(List <OrderProduct> products)
        {
            CurrentUser = UserManager.FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            foreach (OrderProduct product in products)
            {
                StoredProduct storedProduct = _storedProductRepository.GetEntities()
                                              .Where(p => p.UserId == this.CurrentUser.Id && p.ProductId == product.ProductId)
                                              .FirstOrDefault();
                try
                {
                    storedProduct.Quantity += product.Quantity;
                    _storedProductRepository.Update(storedProduct);
                    _storedProductRepository.Save();
                }
                catch (NullReferenceException e)
                {
                    storedProduct = new StoredProduct()
                    {
                        UserId    = CurrentUser.Id,
                        ProductId = product.ProductId,
                        Quantity  = product.Quantity
                    };
                    _storedProductRepository.Insert(storedProduct);
                    _storedProductRepository.Save();
                }
            }
        }
        public ActionResult Edit([Bind(Include = "ProductId,Name,UnitPrice,Category,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                _productRepository.Update(product);
                _productRepository.Save();

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
        public async Task <IActionResult> UpdateArea(Contract.Production request)
        {
            try
            {
                await _areaRepository.Update(request);

                _logService.SendMessagesAsync("ProductionAreaChanged");
                return(Ok(request));
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
        public IActionResult Edit(Production model)
        {
            if (ModelState.IsValid)
            {
                Production production = _productionRepository.GetProduction(model.ProductionId);
                production.ProdInvId    = model.ProdInvId;
                production.ProdQuantity = model.ProdQuantity;
                production.HDPE         = model.HDPE;
                production.LDPE         = model.LDPE;
                production.PP           = model.PP;
                production.T2OR         = model.T2OR;
                production.T2OB         = model.T2OB;
                production.T2OY         = model.T2OY;
                production.Thinner      = model.Thinner;
                production.Wastage      = model.Wastage;
                production.ProdHour     = model.ProdHour;
                production.Date         = model.Date;

                Production updateProduction = _productionRepository.Update(production);
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        // GET: Cart/Return
        public ActionResult Return(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            _orderProductRepository = new OrderProductRepository(new Data.DAL.Context.ApplicationDbContext());
            OrderProduct orderProduct = _orderProductRepository.GetDetails(id);

            orderProduct.Quantity -= 1;

            if (orderProduct.Quantity == 0)
            {
                _orderProductRepository.Delete(id.GetValueOrDefault());
            }
            else
            {
                _orderProductRepository.Update(orderProduct);
            }
            _orderProductRepository.Save();

            return(RedirectToAction("Index"));
        }
Example #7
0
 public bool Update(Production production)
 {
     _repository.Update(production);
     return(_repository.SaveChanges());
 }