Example #1
0
        public ActionResult Delete(Guid rowguid)
        {
            Product item = repository.Products.SingleOrDefault(x => x.rowguid == rowguid);

            if (item != null)
            {
                repository.Delete(item);
                TempData["admin_message"] = string.Format("{0} was deleted", item.Name);
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        public bool Delete(int id)
        {
            var production = _repository.FindById(id);

            _repository.Delete(production);
            return(_repository.SaveChanges());
        }
        public ActionResult CheckoutConfirmed()
        {
            CurrentUser = UserManager.FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
            List <OrderProduct> orderProducts = _orderProductRepository.GetEntities()
                                                .Where(p => p.UserId == this.CurrentUser.Id).ToList();

            if (!BalanceOperations.CanBuy(orderProducts, CurrentUser.Balance))
            {
                TempData["Error"] = "Insufficient credits!";
                return(RedirectToAction("Index"));
            }
            CurrentUser.Balance -= BalanceOperations.GetPrice(orderProducts);
            UserManager.Update(CurrentUser);

            var inventoryController = DependencyResolver.Current.GetService <InventoryController>();

            inventoryController.ControllerContext = new ControllerContext(this.Request.RequestContext, inventoryController);

            inventoryController.Add(orderProducts);

            foreach (OrderProduct product in orderProducts)
            {
                _orderProductRepository.Delete(product.OrderProductId);
            }
            _orderProductRepository.Save();


            return(RedirectToAction("Index", "Inventory"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Product product = _productRepository.GetDetails(id);

            _productRepository.Delete(id);
            _productRepository.Save();

            return(RedirectToAction("Index"));
        }
Example #5
0
        public RedirectToRouteResult Remove(int productId, string returnUrl)
        {
            var cart =
                repository.CartItems.SingleOrDefault(
                    x => x.Customer.EmailAddress == this.ControllerContext.HttpContext.User.Identity.Name &&
                    x.ProductId == productId);

            if (cart != null)
            {
                repository.Delete(cart);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
        public async Task <IActionResult> UpdateProductionOrder(int id, ProdOrderHeaderForDetailDto prodOrderHeaderForDetailDto)
        {
            if (prodOrderHeaderForDetailDto == null)
            {
                return(BadRequest("Empty Body"));
            }

            var prodOrderHeaderFromRepository = await _repository.GetProductionOrder(id);

            if (prodOrderHeaderFromRepository == null)
            {
                return(BadRequest("Production Order not available"));
            }

            prodOrderHeaderFromRepository.UserId = prodOrderHeaderForDetailDto.UserId;

            prodOrderHeaderFromRepository.BusinessPlace = await _repository.Get <BusinessPlace>(prodOrderHeaderForDetailDto.BusinessPlaceId);

            prodOrderHeaderFromRepository.Session = await _repository.Get <ProductionSession>(prodOrderHeaderForDetailDto.SessionId);

            prodOrderHeaderFromRepository.User = await _repository.Get <User>(prodOrderHeaderForDetailDto.UserId);

            prodOrderHeaderFromRepository.RequiredDate  = DateTime.Parse(prodOrderHeaderForDetailDto.RequiredDate);
            prodOrderHeaderFromRepository.EnteredDate   = DateTime.Parse(prodOrderHeaderForDetailDto.EnteredDate);
            prodOrderHeaderFromRepository.IsNotEditable = false;

            foreach (var pod in prodOrderHeaderFromRepository.ProductionOrderDetails)
            {
                _repository.Delete(pod);
            }

            prodOrderHeaderFromRepository.ProductionOrderDetails.Clear();

            foreach (var pod in prodOrderHeaderForDetailDto.ProductionOrderDetails)
            {
                prodOrderHeaderFromRepository.ProductionOrderDetails.Add(new ProductionOrderDetail
                {
                    ItemId      = pod.ItemId,
                    Quantity    = (decimal)pod.Quantity,
                    Description = pod.Description
                });
            }

            if (await _repository.SaveAll())
            {
                return(NoContent());
            }


            throw new System.Exception($"Updating production Order {id} failed on save");
        }
        public async Task <IActionResult> UpdateIngredient(int id, IngredientHeaderForDetailDto ingredientHeaderForDetailDto)
        {
            if (ingredientHeaderForDetailDto == null)
            {
                return(BadRequest(new ErrorModel(1, 400, "empty body")));
            }

            var ingredientHeaderFromRepository = await _repository.GetIngredient(id);

            if (ingredientHeaderFromRepository == null)
            {
                return(BadRequest(new ErrorModel(3, 400, "Ingredient not available")));
            }

            ingredientHeaderFromRepository.ItemId = ingredientHeaderForDetailDto.ItemId;

            ingredientHeaderFromRepository.Description = ingredientHeaderForDetailDto.Description;
            ingredientHeaderFromRepository.Method      = ingredientHeaderForDetailDto.Method;
            ingredientHeaderFromRepository.ServingSize = ingredientHeaderForDetailDto.ServingSize;

            foreach (var pod in ingredientHeaderFromRepository.IngredientsDetail)
            {
                _repository.Delete(pod);
            }

            ingredientHeaderFromRepository.IngredientsDetail.Clear();

            foreach (var pod in ingredientHeaderForDetailDto.IngredientDetails)
            {
                ingredientHeaderFromRepository.IngredientsDetail.Add(new IngredientDetail
                {
                    ItemId   = pod.ItemId,
                    Quantity = (decimal)pod.Quantity
                });
            }

            if (await _repository.SaveAll())
            {
                return(NoContent());
            }


            throw new System.Exception($"Updating Ingredient {id} failed on save");
        }
        // 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 #9
0
        public ActionResult DeleteAddress(Guid rowguid)
        {
            var address = repository.Addresses.SingleOrDefault(x => x.rowguid == rowguid);

            if (address != null)
            {
                if (address.CustomerAddresses != null)
                {
                    address.CustomerAddresses.Clear();
                }
            }
            try
            {
                repository.Delete(address);
                TempData["customer_message"] = "Address has been deleted.";
            }
            catch (Exception ex)
            {
                TempData["customer_message"] = "Error ocured deleting address.";
                return(View("EditAddress", address));
            }
            return(RedirectToAction("Addresses"));
        }
        public async Task <IActionResult> UpdateProductionPlan(int id, ProdPlanHeaderForDetailDto ProdPlanHeaderForDetailDto)
        {
            if (ProdPlanHeaderForDetailDto == null)
            {
                return(BadRequest(new ErrorModel(1, 400, "Empty Body")));
            }
            if (ProdPlanHeaderForDetailDto.ProdOrdrIds == null)
            {
                return(BadRequest(new ErrorModel(2, 400, "Production orders needed")));
            }

            if (ProdPlanHeaderForDetailDto.ProductionPlanDetails == null ||
                ProdPlanHeaderForDetailDto.ProductionPlanRecipes == null ||
                ProdPlanHeaderForDetailDto.ProductionPlanWorkers == null ||
                ProdPlanHeaderForDetailDto.ProductionPlanMachines == null)
            {
                return(BadRequest(new ErrorModel(3, 400, "all nested details required")));
            }


            var planHeaderToUpdate = await _repository.GetProductionPlan(id);

            planHeaderToUpdate.UserId      = ProdPlanHeaderForDetailDto.UserId;
            planHeaderToUpdate.Description = ProdPlanHeaderForDetailDto.Description;

            foreach (var detail in planHeaderToUpdate.ProductionPlanDetails)
            {
                _repository.Delete(detail);
            }

            planHeaderToUpdate.ProductionPlanDetails.Clear();

            foreach (var detail in ProdPlanHeaderForDetailDto.ProductionPlanDetails)
            {
                planHeaderToUpdate.ProductionPlanDetails.Add(new ProductionPlanDetail
                {
                    ItemId      = detail.ItemId,
                    Quantity    = (decimal)detail.Quantity,
                    Description = detail.Description
                });
            }

            foreach (var recipe in planHeaderToUpdate.ProductionPlanRecipes)
            {
                _repository.Delete(recipe);
            }

            planHeaderToUpdate.ProductionPlanRecipes.Clear();

            foreach (var recipe in ProdPlanHeaderForDetailDto.ProductionPlanRecipes)
            {
                planHeaderToUpdate.ProductionPlanRecipes.Add(new ProductionPlanRecipe
                {
                    ItemId      = recipe.ItemId,
                    Quantity    = (decimal)recipe.Quantity,
                    Description = recipe.Description
                });
            }

            foreach (var emp in planHeaderToUpdate.ProductionPlanWorkers)
            {
                _repository.Delete(emp);
            }

            planHeaderToUpdate.ProductionPlanWorkers.Clear();

            foreach (var emp in ProdPlanHeaderForDetailDto.ProductionPlanWorkers)
            {
                planHeaderToUpdate.ProductionPlanWorkers.Add(new ProductionPlanWorker
                {
                    EmployeeId = emp.EmployeeId
                });
            }

            foreach (var mchn in planHeaderToUpdate.ProductionPlanMachines)
            {
                _repository.Delete(mchn);
            }

            planHeaderToUpdate.ProductionPlanMachines.Clear();

            foreach (var mchn in ProdPlanHeaderForDetailDto.ProductionPlanMachines)
            {
                planHeaderToUpdate.ProductionPlanMachines.Add(new ProductionPlanMachine
                {
                    MachineryId = mchn.MachineryId
                });
            }

            if (await _repository.SaveAll())
            {
                var prodsUpdate = await _context.ProductionOrderHeaders.Where(a => a.PlanId == planHeaderToUpdate.Id).ToListAsync();

                foreach (var prod in prodsUpdate)
                {
                    prod.IsNotEditable = false;
                    prod.PlanId        = null;
                    prod.isProcessed   = null;
                }
                await _context.SaveChangesAsync();

                foreach (var prodOrderId in ProdPlanHeaderForDetailDto.ProdOrdrIds)
                {
                    var prodOrder = await _context.ProductionOrderHeaders.FirstOrDefaultAsync(a => a.Id == prodOrderId);

                    prodOrder.IsNotEditable = true;
                    prodOrder.PlanId        = planHeaderToUpdate.Id;
                    prodOrder.isProcessed   = 0;
                }

                if (await _context.SaveChangesAsync() > 0)
                {
                    return(NoContent());
                }
                return(BadRequest(new ErrorModel(4, 400, "Updated production plan, but some error occured")));
            }
            return(BadRequest(new ErrorModel(5, 400, "Could not update production plan")));
        }
Example #11
0
 public void RemoveProduct(int cartItemID)
 {
     repository.Delete(repository.CartItems.SingleOrDefault(x => x.CartItemId == cartItemID));
 }