Ejemplo n.º 1
0
        public async Task <IActionResult> Create(SharedTravelCreateInputViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                var citiesAsKVP = await this.castCollectionsService.GetCitiesAsKeyValuePairs();

                var typesAsKVP = await this.castCollectionsService.GetTravelTypesAsKeyValuePairs();

                var inputModel = new SharedTravelCreateInputViewModel();
                inputModel.Cities        = citiesAsKVP;
                inputModel.TypesOfTravel = typesAsKVP;

                return(this.View(inputModel));
            }

            var userId    = this.userManager.GetUserId(this.User);
            var createdBy = await this.userManager.FindByIdAsync(userId);

            var advertId = await this.sharedTravelsService.CreateAsync(input, userId);

            var model = new ThankYouVIewModel()
            {
                AdvertId = advertId,
                UserName = createdBy.UserName,
            };

            return(this.View("ThankYou", model));
        }
        public async Task <string> CreateAsync(SharedTravelCreateInputViewModel input, string userId)
        {
            var statusId = this.sharedTravelStatusRepository
                           .AllAsNoTracking()
                           .Where(x => x.Name == ServicesConstants.AdvertDefaultStatus)
                           .Select(x => x.Id)
                           .FirstOrDefault();

            var sharedTravelAdvert = new SharedTravelAdvert
            {
                StatusId           = statusId,
                Seats              = input.Seats,
                StartDateAndTime   = input.StartDateAndTime,
                CreatedById        = userId,
                StartDestinationId = input.StartDestinationId,
                EndDestinationId   = input.EndDestinationId,
                SmokeRestriction   = IsTrue(input.SmokeRestriction),
                PlaceForLuggage    = IsTrue(input.PlaceForLuggage),
                WithReturnTrip     = IsTrue(input.WithReturnTrip),
                TypeOfTravelId     = input.TypeOfTravelId,
                Description        = input.Description,
            };

            await this.sharedTravelsRepository.AddAsync(sharedTravelAdvert);

            await this.sharedTravelsRepository.SaveChangesAsync();

            var sharedTravelId = sharedTravelAdvert.Id;

            return(sharedTravelId);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create()
        {
            var citiesAsKVP = await this.castCollectionsService.GetCitiesAsKeyValuePairs();

            var typesAsKVP = await this.castCollectionsService.GetTravelTypesAsKeyValuePairs();

            var inputModel = new SharedTravelCreateInputViewModel();

            inputModel.Cities        = citiesAsKVP;
            inputModel.TypesOfTravel = typesAsKVP;

            return(this.View(inputModel));
        }