Esempio n. 1
0
        public async Task CreateAdAsync(CreateAdInputModel inputModel)
        {
            var imageUrls = inputModel.CreateAdDetailInputModel.Images
                            .Select(async x =>
                                    await cloudinaryService.UploadPictureAsync(x, x.FileName))
                            .Select(x => x.Result)
                            .ToList();

            var ad = mapper.Map <Ad>(inputModel);

            ad.ActiveTo = DateTime.UtcNow.AddDays(GlobalConstants.AdDuration);
            ad.Images   = imageUrls.Select(x => new Image {
                ImageUrl = x
            })
                          .ToList();
            ad.SellerId = usersService.GetCurrentUserId();

            await context.Ads.AddAsync(ad);

            await context.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task <string> CreateAsync(CreateAdInputModel adtInputModel, string userId)
        {
            var ad = new Ad
            {
                CityId         = adtInputModel.CityId,
                City           = await this.citiesRepository.All().FirstOrDefaultAsync(x => x.Id == adtInputModel.CityId),
                IsVip          = false,
                UserId         = userId,
                JobCategoryId  = adtInputModel.JobCategoryId,
                JobCategory    = await this.categoriesRepository.All().FirstOrDefaultAsync(x => x.Id == adtInputModel.JobCategoryId),
                Opinions       = new List <Opinion>(),
                PreparedBudget = adtInputModel.PreparedBudget,
                Title          = adtInputModel.Title,
                Description    = adtInputModel.Description,
            };

            await this.adsRepository.AddAsync(ad);

            await this.adsRepository.SaveChangesAsync();

            return(ad.Id);
        }
Esempio n. 3
0
        public async Task <string> CreateAdAsync(CreateAdInputModel input, string userId)
        {
            if (input.Extras == null)
            {
                input.Extras = "No extras";
            }

            var car = new Car
            {
                Cc               = input.Cc,
                Fuel             = input.Fuel,
                Color            = input.Color,
                Door             = input.Door,
                EuroStandart     = input.EuroStandart,
                Extras           = input.Extras,
                Gearbox          = input.Gearbox,
                Horsepowers      = input.Hp,
                Km               = input.Km,
                Location         = input.Location,
                Make             = input.Make,
                Model            = input.Model,
                Modification     = input.Modification,
                MoreInformation  = input.MoreInformation,
                Price            = input.Price,
                Type             = input.Type,
                Condition        = input.Condition,
                YearOfProduction = DateTime.ParseExact(input.YearOfProduction, "mm.yyyy", CultureInfo.InvariantCulture),
                UserId           = userId,
                ImgsPaths        = GlobalConstants.DefaultImgCar,
                TypeOfVeichle    = input.TypeOfVeichle,
            };

            await this.carRepository.AddAsync(car);

            await this.carRepository.SaveChangesAsync();

            return(car.Id);
        }
Esempio n. 4
0
        public async Task <IActionResult> Create(CreateAdInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                var createModel = new CreateAdInputModel
                {
                    Categories = await this.categoriesService.GetAllCategoriesAsync <CategorySimpleViewModel>(),
                    Cities     = await this.citiesService.GetAllCitiesAsync <CitySimpleViewModel>(),
                };

                return(this.View(createModel));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var newAdId = await this.adsService.CreateAsync(input, user.Id);

            this.TempData["Message"] = SuccessfulyCreatedAd;
            return(this.RedirectToAction(nameof(this.MyAds)));

            // return this.RedirectToAction("GetDetails", new { id = id });
            // TODO: USE SANITIZER WHEN SHOWING AD DETAILS !!!!
        }
Esempio n. 5
0
        public async Task EditAdTests()
        {
            var options       = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var carRepository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));

            var service = new AdService(carRepository);

            var inputModel = new CreateAdInputModel
            {
                Cc               = 1,
                Color            = 0,
                Condition        = Condition.New,
                Door             = Doors.Three,
                EuroStandart     = EuroStandart.Euro1,
                Extras           = "4x4",
                Fuel             = Fuel.Diesel,
                Gearbox          = Gearbox.Automatic,
                Hp               = 1,
                ImgsPaths        = GlobalConstants.DefaultImgCar,
                Km               = 100,
                Location         = Location.Sofia,
                Make             = Make.Audi,
                Model            = "test",
                Modification     = "test",
                MoreInformation  = "test test",
                Price            = 100,
                Type             = Types.Convertible,
                TypeOfVeichle    = TypeOfVeichle.Car,
                YearOfProduction = "01.1999",
            };
            await service.CreateAdAsync(inputModel, "1");

            var car = await carRepository.All().FirstOrDefaultAsync(x => x.Model == "test");

            var oldMake      = car.Make;
            var oldMoreInfo  = car.MoreInformation;
            var oldCc        = car.Cc;
            var editCC       = 3;
            var editMake     = Make.Bmw;
            var editMoreInfo = "edit test";
            var editAd       = new EditAddInputModel
            {
                Id               = car.Id,
                Cc               = editCC,
                Color            = car.Color,
                Door             = car.Door,
                EuroStandart     = car.EuroStandart,
                Extras           = car.Extras,
                Fuel             = car.Fuel,
                Gearbox          = car.Gearbox,
                Hp               = car.Horsepowers,
                Km               = car.Km,
                Location         = car.Location,
                Make             = editMake,
                Model            = car.Model,
                Modification     = car.Modification,
                MoreInformation  = editMoreInfo,
                Price            = car.Price,
                Type             = car.Type,
                Condition        = car.Condition,
                YearOfProduction = car.YearOfProduction.ToString("mm.yyyy"),
                TypeOfVeichle    = car.TypeOfVeichle,
            };
            var edittedCar = await service.EditAd(editAd);

            Assert.Equal(edittedCar.Make, editMake);
            Assert.Equal(edittedCar.Cc, editCC);
            Assert.Equal(edittedCar.MoreInformation, editMoreInfo);
            Assert.NotEqual(edittedCar.Make, oldMake);
            Assert.NotEqual(edittedCar.Cc, oldCc);
            Assert.NotEqual(edittedCar.MoreInformation, oldMoreInfo);
        }