Beispiel #1
0
        public IActionResult Delete(string id)
        {
            var type = _unityOfWork.Type.GetById(Convert.ToInt32(id));
            TypeDeleteViewModel typeToDelete = new TypeDeleteViewModel()
            {
                ID          = type.ID,
                Name        = type.Name,
                Description = type.Description
            };

            typeToDelete.Products = _unityOfWork.Product.getProductsByType(Convert.ToInt32(id));
            return(View(typeToDelete));
        }
Beispiel #2
0
        public IActionResult Delete(TypeDeleteViewModel typeToDelete)
        {
            var myTypeToDelete = _unityOfWork.Type.GetById(typeToDelete.ID);

            typeToDelete.Products = _unityOfWork.Product.getProductsByType(Convert.ToInt32(typeToDelete.ID));

            var deleteAllProducts = typeToDelete.deleteProducts;

            if (deleteAllProducts)
            {
                foreach (var product in typeToDelete.Products)
                {
                    _unityOfWork.Product.Delete(product);
                }
            }
            _unityOfWork.Type.Delete(myTypeToDelete);

            _unityOfWork.Save();
            LoggingController.writeLog(myTypeToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());

            return(RedirectToAction("Index"));
        }