public async Task <IActionResult> Edit(EditLoadViewModel model) { if (this.ModelState.IsValid == false) { var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresEditLoadViewModel>(); var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityEditLoadViewModel>(); var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesLoadEditViewModel>(); LoadEditViewModel inputModel = new LoadEditViewModel() { Countries = countries, Priorities = priorityTypes, TruckTypes = truckTypes, }; var model2 = await this.loadsService.GetLoadDetailsByIdAsync <EditLoadViewModel>(model.Id); model2.InputModel = inputModel; model2.Referer = model.Referer; return(this.View(model2)); } model.InputModel = new LoadEditViewModel(); await this.loadsService.EditLoadAsync(model); return(this.Redirect(model.Referer)); }
public async Task <IActionResult> Edit(string id) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); if (await this.ordersService.CheckOrderOwnerByUserIdAsync(userId, id) == false) { return(this.Redirect("/Identity/Account/AccessDenied")); } var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresEditLoadViewModel>(); var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityEditLoadViewModel>(); var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesLoadEditViewModel>(); LoadEditViewModel inputModel = new LoadEditViewModel() { Countries = countries, Priorities = priorityTypes, TruckTypes = truckTypes, }; EditLoadViewModel model = await this.loadsService.GetLoadDetailsByIdAsync <EditLoadViewModel>(id); model.InputModel = inputModel; string referer = this.Request.Headers["Referer"].ToString(); model.Referer = referer; return(this.View(model)); }
public async Task EditLoadAsync(EditLoadViewModel model) { bool isNull = model.GetType().GetProperties() .All(p => p.GetValue(model) != null); if (isNull == false) { throw new ArgumentNullException("Model param is null"); } var order = await this.orderRepository.All().SingleOrDefaultAsync(x => x.Id == model.Id); if (order == null) { throw new ArgumentNullException("Load is null"); } order.AddressFrom = this.addressesService.GetAddressOrCreateByCoutryNameAndTownName(model.CountryFrom, model.TownFrom); this.orderRepository.Update(order); this.orderRepository.SaveChages(); order.AddressTo = this.addressesService.GetAddressOrCreateByCoutryNameAndTownName(model.CountryTo, model.TownTo); order.LoadTime = model.LoadTime; order.ExpireTime = model.ExpireTime; order.Price = model.Price; order.TruckType = await this.truckTypesService.GetTruckTypeByNameAsync(model.TruckTypeName); order.Circle = model.Circle; order.Load.Weight = model.LoadWeight; order.Load.Volume = model.LoadVolume; order.Load.DeliveryTime = model.LoadDeliveryTime; order.Priority = await this.priorityTypesService.GetPriorityTypeByNameAsync(model.Priority); this.orderRepository.Update(order); this.orderRepository.SaveChages(); }
public async Task EditLoadAsync_WithCorrectData_ShouldEditLoad() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); await repository.AddAsync(new Order() { Id = "asdasd", Load = new Load(), }); await context.SaveChangesAsync(); EditLoadViewModel model = new EditLoadViewModel() { Id = "asdasd", CountryFrom = "Bulgaria", TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", InputModel = new LoadEditViewModel(), }; await service.EditLoadAsync(model); var actualResult = await repository.All().ToListAsync(); Assert.Equal(12312231, actualResult[0].Price); }
public async Task <IActionResult> Edit(string id) { var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresEditLoadViewModel>(); var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityEditLoadViewModel>(); var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesLoadEditViewModel>(); LoadEditViewModel inputModel = new LoadEditViewModel() { Countries = countries, Priorities = priorityTypes, TruckTypes = truckTypes, }; EditLoadViewModel model = await this.loadsService.GetLoadDetailsByIdAsync <EditLoadViewModel>(id); model.InputModel = inputModel; string referer = this.Request.Headers["Referer"].ToString(); model.Referer = referer; return(this.View(model)); }
public async Task EditLoadAsync_WithIncorectOrderId_ShouldReturnArgumentNullException() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); await repository.AddAsync(new Order() { Id = "asdasd", Load = new Load(), }); await context.SaveChangesAsync(); EditLoadViewModel model = new EditLoadViewModel() { Id = "asd", CountryFrom = "Bulgaria", TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", InputModel = new LoadEditViewModel(), }; await Assert.ThrowsAsync <ArgumentNullException>(() => service.EditLoadAsync(model)); }