Ejemplo n.º 1
0
        public async Task <IActionResult> Create(string id, JoinRequestCreateBindingModel model)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var rideServiceModel = await this.ridesService.GetAsync(id);

            if (rideServiceModel == null ||
                !this.ridesService.CanUserAccessRide(rideServiceModel, this.User?.Identity?.Name))
            {
                return(this.NotFound());
            }

            if (!this.joinRequestsService.CanUserSendJoinRequest(rideServiceModel, this.User?.Identity?.Name))
            {
                return(this.RedirectToAction("Details", "Rides", new { id }));
            }

            if (!this.ModelState.IsValid)
            {
                model.RideId    = rideServiceModel.Id;
                model.RideTitle = rideServiceModel.Title;

                return(this.View(model));
            }

            var serviceModel = Mapper.Map <JoinRequestServiceModel>(model);

            serviceModel.User = new PoolItUserServiceModel
            {
                UserName = this.User.Identity.Name
            };

            serviceModel.RideId = id;
            serviceModel.SentOn = DateTime.UtcNow;

            var result = await this.joinRequestsService.CreateAsync(serviceModel);

            if (result)
            {
                this.Success(NotificationMessages.JoinRequestCreated);
            }
            else
            {
                this.Error(NotificationMessages.JoinRequestCreateError);
            }

            return(this.RedirectToAction("Details", "Rides", new { id }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(string id)
        {
            var rideServiceModel = await this.ridesService.GetAsync(id);

            if (rideServiceModel == null ||
                !this.ridesService.CanUserAccessRide(rideServiceModel, this.User?.Identity?.Name))
            {
                return(this.NotFound());
            }

            if (!this.joinRequestsService.CanUserSendJoinRequest(rideServiceModel, this.User?.Identity?.Name))
            {
                return(this.RedirectToAction("Details", "Rides", new { id }));
            }

            var bindingModel = new JoinRequestCreateBindingModel
            {
                RideId    = rideServiceModel.Id,
                RideTitle = rideServiceModel.Title
            };

            return(this.View(bindingModel));
        }