public async Task CreatePartAsync(CreatePartModel cpm) { if (string.IsNullOrWhiteSpace(cpm.Name) || cpm.Name.Length < 2) { throw new ArgumentException("Part name not valid.(Must be at least 2 symbols)"); } else if (cpm.Price < 0 || cpm.Price > 100000) { throw new ArgumentException("Price must be between 0 and 100000."); } else if (cpm.Quantity <= 0 || cpm.Quantity > 100) { throw new ArgumentException("Quantity not valid."); } var part = new Part() { Name = cpm.Name, Price = cpm.Price, Quantity = cpm.Quantity, VehicleModel = cpm.VehicleModel, }; await this.partRepository.AddAsync(part); await this.partRepository.SaveChangesAsync(); }
public async Task <IActionResult> Create(CreatePartModel cpm) { try { if (!this.partService.IsItPartWithModelCreated(cpm.Name, cpm.VehicleModel)) { await this.partService.CreatePartAsync(cpm); } } catch (Exception message) { return(this.Problem(message.ToString())); } return(this.Redirect("/Warehouse/All")); }
public async Task CreatePartAsyncTest() { var part = new CreatePartModel() { Name = "Bonnet", Price = 400.00, Quantity = 1, VehicleModel = VehicleModel.Model_3, }; await this.partService.CreatePartAsync(part); var expect = this.partRepository.All().CountAsync().GetAwaiter().GetResult(); var result = this.partService.CountParts(part.Name); Assert.Equal(expect, result); }
public IActionResult Create() { var viewModel = new CreatePartModel(); return(this.View(viewModel)); }