Ejemplo n.º 1
0
        public IActionResult Create(PartFormModel model)
        {
            var quantity = model.Quantity > 0 ? model.Quantity : 1;

            this.parts.Create(model.Name, model.Price, model.SupplierId, quantity);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 2
0
        public IActionResult Details(int id) => this.View(); // TODO

        public IActionResult Create()
        {
            var model = new PartFormModel {
                Suppliers = this.GetSuppliersSelectListItems()
            };

            return(this.View(PartFormView, model));
        }
Ejemplo n.º 3
0
        public IActionResult Create()
        {
            var model = new PartFormModel
            {
                SuppliersDropdown = this.GetSuppliersDropDown()
            };

            return(this.View(model));
        }
        public IActionResult Create()
        {
            PartFormModel model = new PartFormModel
            {
                Suppliers = this.GetAllSupplierListItems()
            };

            return(View(model));
        }
Ejemplo n.º 5
0
        public IActionResult Edit(int supplierId, int id, PartFormModel model)
        {
            this.partService.Edit(
                id,
                model.Name,
                model.Price,
                model.Quantity);

            return(RedirectToAction(nameof(GetAllBySupplier), supplierId));
        }
Ejemplo n.º 6
0
        public IActionResult Edit(int id, PartFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.IsEditMode = true;
                return(View(model));
            }
            this.parts.Edit(id, model.Price, model.Quantity);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 7
0
        public IActionResult Create(PartFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Suppliers = this.GetSupplierListItems();
                return(View(model));
            }

            this.partService.Create(model.Name, model.Price, model.Quantity, model.SupplierId);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 8
0
        public IActionResult Edit(int supplierId, int id)
        {
            PartModel partModel = this.partService.GetById(id);

            PartFormModel partFormModel = new PartFormModel
            {
                Name     = partModel.Name,
                Price    = partModel.Price,
                Quantity = partModel.Quantity
            };

            return(View(partFormModel));
        }
Ejemplo n.º 9
0
        public IActionResult Edit(int id, PartFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.IsEdit = true;
                return(this.View(model));
            }

            this.parts.Edit(id, model.Price, model.Quantity);

            this.logs.Create(this.User.Identity.Name, MethodBase.GetCurrentMethod().Name, ModelType);

            return(this.RedirectToAction(nameof(this.All)));
        }
Ejemplo n.º 10
0
        public IActionResult Create(PartFormModel model)
        {
            if (!this.ModelState.IsValid)
            {
                model.AllSuppliers = this.GetSupplierListItems();
                return(this.View(model));
            }

            this.parts
            .Create(model.Name, model.Price, model.Quantity, model.SupplierId);

            this.logs.Create(this.User.Identity.Name, MethodBase.GetCurrentMethod().Name, ModelType);

            return(this.RedirectToAction(nameof(this.All)));
        }
Ejemplo n.º 11
0
        public IActionResult Edit(int id, PartFormModel model)
        {
            if (!this.ModelState.IsValid)
            {
                model.IsEdit = true;
                return(this.View(model));
            }

            this.partService.Update(
                id,
                model.Price,
                model.Quantity);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 12
0
        public IActionResult Edit(int id, PartFormModel partForm)
        {
            if (!ModelState.IsValid)
            {
                partForm.IsEdit = true;
                return(View(partForm));
            }

            this.parts.Edit(
                id,
                partForm.Price,
                partForm.Quantity);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 13
0
 public IActionResult Add(PartFormModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(new PartFormModel
         {
             Suppliers = Suppliers.All().Select(s => new SelectListItem
             {
                 Text = s.Name,
                 Value = s.Id.ToString()
             })
         }));
     }
     this.Parts.Add(model.Name, model.Price, model.SupplierId, model.Quantity);
     return(RedirectToAction(nameof(All)));
 }
Ejemplo n.º 14
0
        public IActionResult Edit(int id, PartFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool partExists = this.Parts.Exists(id);

            if (!partExists)
            {
                return(NotFound());
            }

            this.Parts.Edit(id, model.Price, model.Quantity);
            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 15
0
        public IActionResult Delete(int id, PartFormModel model)
        {
            if (!this.partService.Exists(id))
            {
                return(this.RedirectToAction(nameof(Index)));
            }

            try
            {
                this.partService.Remove(id);
                return(this.RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(this.View(PartFormView, model));
            }
        }
Ejemplo n.º 16
0
        public IActionResult Create(PartFormModel model)
        {
            //if (true) // Check if supplier doesn't exist - OPTIONAL
            //{
            //    ModelState.AddModelError(nameof(PartFormModel.Suppliers), "Invalid supplier.");
            //}

            if (!ModelState.IsValid)
            {
                model.Suppliers = this.GetSupplierListItems();
                return(View(model));
            }

            this.parts.Create(model.Name, model.Price, model.Quantity, model.SupplierId);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 17
0
        public IActionResult Edit(int id)
        {
            var part = this.partService.GetById(id);

            if (part == null)
            {
                return(RedirectToAction(nameof(All)));
            }

            var model = new PartFormModel
            {
                Name     = part.Name,
                Price    = part.Price,
                Quantity = part.Quantity,
                IsEdit   = true
            };

            return(this.View(model));
        }
        public IActionResult Edit(int id)
        {
            PartDetailsServiceModel part = this.partService.GetPartById(id);

            if (part == null)
            {
                return(NotFound());
            }

            PartFormModel model = new PartFormModel
            {
                Name     = part.Name,
                Price    = part.Price,
                Quantity = part.Quantity,
                IsEdit   = true
            };

            return(View(model));
        }
Ejemplo n.º 19
0
        public IActionResult Create(PartFormModel modelPart)
        {
            //ModelState.AddModelError(nameof(PartFormModel.SupplierId), "Invalid supplier.");


            if (!ModelState.IsValid)
            {
                modelPart.SuppliersList = GetSupplierListItems();
                return(View(modelPart));
            }

            this.parts.Create(
                modelPart.Name,
                modelPart.Price,
                modelPart.Quantity,
                modelPart.SupplierId);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 20
0
        public IActionResult Delete(int id, PartFormModel partModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(partModel));
            }

            var partExists = this.parts.Exists(id);

            if (!partExists)
            {
                return(NotFound());
            }

            var result = this.parts.DeletePart(id);

            TempData.AddSuccessMessage("You have successfully removed your part.");

            return(this.RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 21
0
        public IActionResult Edit(int id, PartFormModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(editModel));
            }

            var partExists = this.parts.Exists(id);

            if (!partExists)
            {
                return(NotFound());
            }

            this.parts.Edit(id, editModel.Name, editModel.Price, editModel.Condition, editModel.ImageUrl);

            TempData.AddSuccessMessage("You have succesfully edited your part.");

            return(this.RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 22
0
        public IActionResult Create(PartFormModel model)
        {
            if (!this.supplierService.Exists(model.SupplierId))
            {
                this.ModelState.AddModelError(nameof(PartFormModel.SupplierId), "Invalid Supplier");
            }

            if (!this.ModelState.IsValid)
            {
                model.SuppliersDropdown = this.GetSuppliersDropDown();
                return(this.View(model));
            }

            this.partService.Create(
                model.Name,
                model.Price,
                model.Quantity,
                model.SupplierId);

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 23
0
        public IActionResult Create(PartFormModel formModel)
        {
            if (!this.suppliers.IdExist(formModel.SupplierId))
            {
                ModelState.AddModelError(nameof(PartFormModel.SupplierId), "Invalid supplier.");
            }

            if (!ModelState.IsValid)
            {
                formModel.Suppliers = GetSupplierListItems();
                return(this.View(formModel));
            }

            this.parts.Create(
                formModel.Name,
                formModel.Price,
                formModel.Quantity,
                formModel.SupplierId);

            return(this.RedirectToAction(nameof(All)));
        }
Ejemplo n.º 24
0
        public IActionResult Edit(int id, PartFormModel model)
        {
            if (!this.partService.Exists(id))
            {
                return(this.RedirectToAction(nameof(Index)));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(PartFormView, model));
            }

            try
            {
                this.partService.Update(id, model.Price, model.Quantity);
                return(this.RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(this.View(PartFormView, model));
            }
        }
Ejemplo n.º 25
0
        public IActionResult Create(PartFormModel addPartModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(addPartModel));
            }

            var success = this.parts.Add(
                addPartModel.Name,
                addPartModel.Price,
                addPartModel.Condition,
                addPartModel.ImageUrl,
                this.User.Identity.GetUserId());

            if (!success)
            {
                return(this.BadRequest());
            }

            TempData.AddSuccessMessage($"Your part {addPartModel.Name} has been successfully added for sale.");

            return(this.RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 26
0
        public IActionResult Edit(int Id, PartFormModel modelPart)
        {
            if (!ModelState.IsValid)
            {
                modelPart.SuppliersList = GetSupplierListItems(modelPart.SupplierId);
                return(View(modelPart));
            }

            bool partExist = this.parts.Exists(Id);

            if (!partExist)
            {
                return(NotFound());
            }

            this.parts.Edit(
                Id,
                modelPart.Price,
                modelPart.Quantity
                );

            return(RedirectToAction(nameof(All)));
        }
Ejemplo n.º 27
0
        public IActionResult Create(PartFormModel model)
        {
            if (!this.supplierService.Exists(model.SupplierId))
            {
                this.ModelState.AddModelError(nameof(PartFormModel.SupplierId), "Invalid supplier.");
            }

            if (!this.ModelState.IsValid)
            {
                model.Suppliers = this.GetSuppliersSelectListItems();
                return(this.View(PartFormView, model));
            }

            try
            {
                this.partService.Create(model.Name, model.Price, model.Quantity, model.SupplierId);
                return(this.RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                model.Suppliers = this.GetSuppliersSelectListItems();
                return(this.View(PartFormView, model));
            }
        }