public IActionResult Create()
        {
            var model = new AddPartModel
            {
                Suppliers = this.supplierService.AllSuppliers().ToList()
            };

            return(View(model));
        }
Example #2
0
        public AddPartModel GetPartModelWithSuppliers()
        {
            AddPartModel model = new AddPartModel()
            {
                Suppliers = this.db.Suppliers.Select(s => new SupplierSelectModel()
                {
                    Id = s.Id, Name = s.Name
                })
            };

            return(model);
        }
Example #3
0
        public void AddPart(AddPartModel model)
        {
            this.db.Parts.Add(new Part()
            {
                Name       = model.Name,
                Price      = model.Price.Value,
                Quantity   = model.Quantity.Value,
                SupplierId = model.SupplierId.Value
            });

            this.db.SaveChanges();
        }
Example #4
0
        public IActionResult Add(AddPartModel model)
        {
            if (this.ModelState.IsValid)
            {
                this.partService.AddPart(model);

                return(RedirectToAction("Add"));
            }

            model.Suppliers = this.partService.GetPartModelWithSuppliers().Suppliers;

            return(this.View(model));
        }
        public IActionResult Create(AddPartModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Suppliers = this.supplierService.AllSuppliers().ToList();
                return(View(model));
            }

            var quantity = (model.Quantity == null ? 1 : int.Parse(model.Quantity.ToString()));

            var success = this.partService.Create(model.Name, model.Price, model.SupplierId, quantity);

            if (success)
            {
                this.logService.Create(User.Identity.Name, "Create", "Part");
                return(RedirectToAction(nameof(AllParts)));
            }
            else
            {
                ModelState.AddModelError(nameof(AddPartModel.SupplierId), "Invalid Supplier!");
                model.Suppliers = this.supplierService.AllSuppliers().ToList();
                return(View(model));
            }
        }
Example #6
0
        public IActionResult Add()
        {
            AddPartModel model = this.partService.GetPartModelWithSuppliers();

            return(this.View(model));
        }