Example #1
0
        public async Task <string> CreateFromAdAsync(CreateOfferInputModel inputModel)
        {
            var applicationUserId = this.adsRepository
                                    .All()
                                    .Where(x => x.Id == inputModel.AdId)
                                    .Select(u => u.UserId)
                                    .FirstOrDefault();

            var newOffer = new Offer
            {
                AdId = inputModel.AdId,
                ApplicationUserId   = applicationUserId,
                Description         = inputModel.Description,
                Price               = inputModel.Price,
                SpecialistDetailsId = inputModel.SpecialistDetailsId,
                StartDate           = inputModel.StartDate,
                ExpirationDate      = inputModel.ExpirationDate,
            };

            await this.offersRepository.AddAsync(newOffer);

            await this.offersRepository.SaveChangesAsync();

            return(newOffer.Id);
        }
Example #2
0
        public async Task<IActionResult> Create(CreateOfferInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(inputModel);
            }

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

            if (inputModel.PhoneNumber != user.PhoneNumber)
            {
                user.PhoneNumber = inputModel.PhoneNumber;
                await this.userManager.UpdateAsync(user);
            }

            inputModel.SpecialistDetailsId = user.SpecialistDetailsId;

            // If the offer comes from an Ad
            if (inputModel.AdId != null)
            {
                await this.offersService.CreateFromAdAsync(inputModel);
            }

            // The offer comes from an Inquiry
            else
            {
                await this.offersService.CreateFromInquiryAsync(inputModel);
            }

            return this.Redirect("/");
        }
Example #3
0
        public async Task<IActionResult> Create(CreateOfferViewModel viewModel)
        {
            var specialist = await this.userManager.GetUserAsync(this.User);
            var userId = string.Empty;

            // The specialist can make an offer in two ways - from inquiry/from Ad. If the offer is being made from an inquiry, the Ad is null.
            // The logic of the app: only 1 offer by Ad / many offers by inquiry
            // viewModel.Id => offer ID
            if (viewModel.Id != null)
            {
                userId = await this.adsService.GetUserIdByAdIdAsync(viewModel.Id);
                var existingOffer = await this.offersService.GetExistingOfferAsync<ExistingOfferViewModel>(viewModel.Id, userId, specialist.SpecialistDetailsId);

                if (existingOffer != null)
                {
                    return this.View(nameof(this.ExistingOffer), existingOffer);
                }
            }
            else
            {
                userId = viewModel.ApplicationUserId;
            }

            var inputModel = new CreateOfferInputModel
            {
                SpecialistDetailsId = specialist.SpecialistDetailsId,
                ApplicationUserId = userId,
                AdId = viewModel.Id,
                InquiryId = viewModel.InquiryId,
                PhoneNumber = specialist.PhoneNumber,
            };

            return this.View(inputModel);
        }
        public IActionResult Create(CreateOfferInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }
            var username = this.User.Identity.Name;

            this.offerService.CreateOffer(model.Price, model.StartDate, model.EndDate, model.Comment, model.JobId, username);


            return(this.Redirect(Constants.homeUrl));
        }
Example #5
0
        public async Task CreateFromInquiryAsync(CreateOfferInputModel inputModel)
        {
            var newOffer = new Offer
            {
                InquiryId           = inputModel.InquiryId,
                ApplicationUserId   = inputModel.ApplicationUserId,
                Description         = inputModel.Description,
                Price               = inputModel.Price,
                SpecialistDetailsId = inputModel.SpecialistDetailsId,
                StartDate           = inputModel.StartDate,
                ExpirationDate      = inputModel.ExpirationDate,
            };

            await this.offersRepository.AddAsync(newOffer);

            await this.offersRepository.SaveChangesAsync();
        }
Example #6
0
        public async Task CreateFromInquiryAsync_ShouldWorkCorrectly()
        {
            AutoMapperConfig.RegisterMappings(typeof(ExistingOfferViewModel).Assembly);
            var applicationUserId = "1";

            var createInputModel = new CreateOfferInputModel
            {
                ApplicationUserId   = "1",
                InquiryId           = "1",
                SpecialistDetailsId = "specialistId",
                Description         = "Offer from inquiry",
            };

            await this.service.CreateFromInquiryAsync(createInputModel);

            var allUserOffers = await this.service.GetAllUserOffersAsync <ExistingOfferViewModel>(applicationUserId);

            var expectedUserOffersCount = 2;

            Assert.Equal(expectedUserOffersCount, allUserOffers.Count());
        }
Example #7
0
        public async Task CreateFromAdAsync_ShouldWorkCorrectly()
        {
            AutoMapperConfig.RegisterMappings(typeof(ExistingOfferViewModel).Assembly);
            var newAd = new Ad
            {
                Id             = "3",
                UserId         = "1",
                CityId         = 1,
                Description    = "Ново!",
                JobCategoryId  = 1,
                PreparedBudget = "2500лв.",
            };

            await this.DbContext.AddAsync(newAd);

            await this.DbContext.SaveChangesAsync();

            var inputModel = new CreateOfferInputModel
            {
                AdId = "3",
                ApplicationUserId   = "1",
                SpecialistDetailsId = "specialistId",
                Price          = 500,
                Description    = "Предлагам незабравима услуга!",
                ExpirationDate = DateTime.UtcNow.AddDays(2),
            };

            var desiredAdId         = "3";
            var applicationUserId   = "1";
            var specialistDetailsId = "specialistId";

            var newOfferId = await this.service.CreateFromAdAsync(inputModel);

            var checkForNewOffer = await this.service.GetExistingOfferAsync <ExistingOfferViewModel>(desiredAdId, applicationUserId, specialistDetailsId);

            Assert.Equal(checkForNewOffer.Id, newOfferId);
        }