예제 #1
0
        public async Task <IActionResult> CreateTruck(AddTrucksInputModel model)
        {
            if (this.ModelState.IsValid == false)
            {
                var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresCreateTruckViewModel>();

                var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityTruckCreateViewModel>();

                var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesTruckCreateViewModel>();

                TruckCreateViewModel inputModel = new TruckCreateViewModel()
                {
                    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 TruckCreateViewModel();
            await this.trucksService.CreateTruckAsync(model, userId);

            model.SteuUserId = userId;

            return(this.Redirect("/Trucks/AllTrucks"));
        }
예제 #2
0
        public async Task <IActionResult> CreateTruck()
        {
            var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresCreateTruckViewModel>();

            var priorityTypes = await this.priorityTypesService.GetAllPriorityAsync <AllPriorityTruckCreateViewModel>();

            var truckTypes = await this.truckTypesService.GetAllTruckTypesAsync <AllTruckTypesTruckCreateViewModel>();

            TruckCreateViewModel inputModel = new TruckCreateViewModel()
            {
                Countries  = countries,
                Priorities = priorityTypes,
                TruckTypes = truckTypes,
            };

            AddTrucksInputModel model = new AddTrucksInputModel()
            {
                InputModel = inputModel,
            };

            string referer = this.Request.Headers["Referer"].ToString();

            model.Referer = referer;

            return(this.View(model));
        }
예제 #3
0
        public async Task CreateTruckAsyncTest_WithNullModelPropery_ShouldReturnArgumentNullException()
        {
            var           context = SteuDbContextInMemoryFactory.InitializeContext();
            TrucksService service = IntializeLoadService(context);

            AddTrucksInputModel model = new AddTrucksInputModel()
            {
                CountryFrom   = null,
                TownFrom      = "Sofia",
                CountryTo     = "Croatia",
                TownTo        = "Zagreb",
                TruckTypeName = "Normal",
                SteuUserId    = "asdasd",
                Priority      = "Normal",
                Circle        = false,
                ExpireTime    = DateTime.UtcNow,
                InputModel    = new TruckCreateViewModel(),
                LoadTime      = DateTime.UtcNow,
                MaxVolume     = 100,
                MaxLoad       = 20000,
                Price         = 12312231,
                Referer       = "dasada",
            };

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.CreateTruckAsync(model, "asdasd"));
        }
예제 #4
0
        public async Task CreateTruckAsyncTest_WithCorrectData_ShouldReturnTruck()
        {
            var           context    = SteuDbContextInMemoryFactory.InitializeContext();
            TrucksService service    = IntializeLoadService(context);
            var           repository = new EfDeletableEntityRepository <Order>(context);

            AddTrucksInputModel model = new AddTrucksInputModel()
            {
                CountryFrom   = "Bulgaria",
                TownFrom      = "Sofia",
                CountryTo     = "Croatia",
                TownTo        = "Zagreb",
                TruckTypeName = "Normal",
                SteuUserId    = "asdasd",
                Priority      = "Normal",
                Circle        = false,
                ExpireTime    = DateTime.UtcNow,
                InputModel    = new TruckCreateViewModel(),
                LoadTime      = DateTime.UtcNow,
                MaxVolume     = 100,
                MaxLoad       = 20000,
                Price         = 12312231,
                Referer       = "dasada",
            };

            await service.CreateTruckAsync(model, "asdasd");

            var actualResult = await repository.All().ToListAsync();

            Assert.Single(actualResult);
        }
예제 #5
0
        public async Task CreateTruckAsync(AddTrucksInputModel 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),
                Truck       = new Truck()
                {
                    MaxLoad   = model.MaxLoad,
                    MaxVolume = model.MaxVolume,
                },
                Priority = await this.priorityTypesService.GetPriorityTypeByNameAsync(model.Priority),
            };

            await this.orderRepository.AddAsync(order);

            await this.orderRepository.SaveChangesAsync();
        }