public async Task <IActionResult> CreateLoad(AddLoadInputModel model) { if (this.ModelState.IsValid == false) { var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresCreateLoadViewModel>(); var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityLoadCreateViewModel>(); var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesLoadCreateViewModel>(); LoadCreateViewModel inputModel = new LoadCreateViewModel() { Countries = countries, Priorities = priorityTypes, TruckTypes = truckTypes, }; model.InputModel = inputModel; return(this.View(model)); } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); model.SteuUserId = userId; model.InputModel = new LoadCreateViewModel(); await this.loadsService.CreateLoadAsync(model, userId); return(this.Redirect("/Loads/AllLoads")); }
public async Task <IActionResult> CreateLoad() { var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresCreateLoadViewModel>(); var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityLoadCreateViewModel>(); var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesLoadCreateViewModel>(); LoadCreateViewModel inputModel = new LoadCreateViewModel() { Countries = countries, Priorities = priorityTypes, TruckTypes = truckTypes, }; AddLoadInputModel model = new AddLoadInputModel() { InputModel = inputModel, }; string referer = this.Request.Headers["Referer"].ToString(); model.Referer = referer; return(this.View(model)); }
public async Task CreateLoadAsyncTest_WithNullModelPropery_ShouldReturnArgumentNullException() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); AddLoadInputModel model = new AddLoadInputModel() { CountryFrom = null, TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", SteuUserId = "asdasd", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, InputModel = new LoadCreateViewModel(), LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", }; await Assert.ThrowsAsync <ArgumentNullException>(() => service.CreateLoadAsync(model, "asdasd")); }
public async Task CreateLoadAsyncTest_WithCorrectData_ShouldReturnLoad() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); AddLoadInputModel model = new AddLoadInputModel() { CountryFrom = "Bulgaria", TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", SteuUserId = "asdasd", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, InputModel = new LoadCreateViewModel(), LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", }; await service.CreateLoadAsync(model, "asdasd"); var actualResult = await repository.All().ToListAsync(); Assert.Single(actualResult); }
public async Task CreateLoadAsync(AddLoadInputModel model, string userId) { if (userId == null) { throw new ArgumentNullException("User is null"); } bool isNull = model.GetType().GetProperties() .All(p => p.GetValue(model) != null); if (isNull == false) { throw new ArgumentNullException("Model param is null"); } Order order = new Order() { AddressFrom = this.addressesService.GetAddressOrCreateByCoutryNameAndTownName(model.CountryFrom, model.TownFrom), AddressTo = this.addressesService.GetAddressOrCreateByCoutryNameAndTownName(model.CountryTo, model.TownTo), LoadTime = model.LoadTime, ExpireTime = model.ExpireTime, Price = model.Price, TruckType = await this.truckTypesService.GetTruckTypeByNameAsync(model.TruckTypeName), Circle = model.Circle, SteuUser = await this.usersService.GetUserByIdAsync(userId), Load = new Load() { Weight = model.LoadWeight, Volume = model.LoadVolume, DeliveryTime = model.LoadDeliveryTime, }, Priority = await this.priorityTypesService.GetPriorityTypeByNameAsync(model.Priority), }; await this.orderRepository.AddAsync(order); await this.orderRepository.SaveChangesAsync(); }