public async Task <IActionResult> AddCargo(CargoInputModel input) { if (!this.ModelState.IsValid) { input = this.cargosService.LoadInputModel(input); return(this.View(input)); } await this.cargosService.AddCargoAsync(input); return(this.RedirectToAction(GlobalConstants.Index)); }
public CargoInputModel LoadInputModel(CargoInputModel model = null) { if (model is null) { model = new CargoInputModel(); } model.TypeItems = this.types.AllAsNoTracking() .Select(ct => new System.Collections.Generic.KeyValuePair <string, string>(ct.Id.ToString(), ct.Name)) .ToList(); model.LoadingBodyItems = this.loadingBodies.AllAsNoTracking() .Select(lb => new System.Collections.Generic.KeyValuePair <string, string>(lb.Id.ToString(), lb.Name)) .ToList(); return(model); }
public async Task <string> AddCargoAsync(CargoInputModel input) { var cargo = new Cargo { Name = input.Name, TypeId = input.TypeId, VehicleTypeId = null, LoadingBodyId = input.LoadingBodyId == 0 ? null : input.LoadingBodyId, Lenght = input.Lenght, Width = input.Width, Height = input.Height, WeightGross = input.WeightGross, WeightNet = input.WeightNet, Cubature = input.Cubature, Quantity = input.Quantity, Details = input.Details, }; await this.cargos.AddAsync(cargo); await this.cargos.SaveChangesAsync(); return(cargo.Id); }