public IActionResult Create() { var model = new AddPartModel { Suppliers = this.supplierService.AllSuppliers().ToList() }; return(View(model)); }
public AddPartModel GetPartModelWithSuppliers() { AddPartModel model = new AddPartModel() { Suppliers = this.db.Suppliers.Select(s => new SupplierSelectModel() { Id = s.Id, Name = s.Name }) }; return(model); }
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(); }
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)); } }
public IActionResult Add() { AddPartModel model = this.partService.GetPartModelWithSuppliers(); return(this.View(model)); }