Example #1
0
        public async Task <IActionResult> Edit(EditTruckViewModel model)
        {
            if (this.ModelState.IsValid == false)
            {
                var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresEditTruckViewModel>();

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

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

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

                EditTruckViewModel model2 = await this.trucksService.GetTruckDetailsByIdAsync <EditTruckViewModel>(model.Id);

                model2.InputModel = inputModel;
                model2.Referer    = model.Referer;
                return(this.View(model2));
            }

            model.InputModel = new TruckEditViewModel();

            await this.trucksService.EditTruckAsync(model);

            return(this.Redirect(model.Referer));
        }
Example #2
0
        public async Task EditTruckAsync(EditTruckViewModel 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("Truck 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.Truck.MaxLoad   = model.MaxLoad;
            order.Truck.MaxVolume = model.MaxVolume;
            order.Priority        = await this.priorityTypesService.GetPriorityTypeByNameAsync(model.Priority);

            this.orderRepository.Update(order);
            this.orderRepository.SaveChages();
        }
Example #3
0
        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 <AllCountiresEditTruckViewModel>();

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

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

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

            EditTruckViewModel model = await this.trucksService.GetTruckDetailsByIdAsync <EditTruckViewModel>(id);

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

            model.Referer = referer;

            return(this.View(model));
        }
Example #4
0
        public async Task EditTruckAsync_WithIncorectOrderId_ShouldReturnArgumentNullException()
        {
            var           context    = SteuDbContextInMemoryFactory.InitializeContext();
            TrucksService service    = IntializeLoadService(context);
            var           repository = new EfDeletableEntityRepository <Order>(context);

            await repository.AddAsync(new Order()
            {
                Id    = "asdasd",
                Truck = new Truck(),
            });

            await context.SaveChangesAsync();

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

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.EditTruckAsync(model));
        }
Example #5
0
        public async Task EditAsync(EditTruckViewModel truckModel)
        {
            var truck = AutoMapperConfig.MapperInstance.Map <Truck>(truckModel);

            this.trucksRepository.Update(truck);
            await this.trucksRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> Edit(EditTruckViewModel truckModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(truckModel));
            }

            truckModel.ManufacturedOn = new DateTime(truckModel.Year, truckModel.Month, 1);
            await this.trucksService.EditAsync(truckModel);

            return(this.RedirectToAction("MyTrucks"));
        }
Example #7
0
        public async Task EditTruckAsync_WithCorrectData_ShouldEditTruck()
        {
            var           context    = SteuDbContextInMemoryFactory.InitializeContext();
            TrucksService service    = IntializeLoadService(context);
            var           repository = new EfDeletableEntityRepository <Order>(context);

            await repository.AddAsync(new Order()
            {
                Id    = "asdasd",
                Truck = new Truck(),
            });

            await context.SaveChangesAsync();

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

            await service.EditTruckAsync(model);

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

            Assert.Equal(12312231, actualResult[0].Price);
        }
Example #8
0
        public async Task <IActionResult> Edit(string id)
        {
            var countries = await this.countriesService.GetAllCountriesAsync <AllCountiresEditTruckViewModel>();

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

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

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

            EditTruckViewModel model = await this.trucksService.GetTruckDetailsByIdAsync <EditTruckViewModel>(id);

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

            model.Referer = referer;

            return(this.View(model));
        }