public override async Task <IActionResult> Delete(int id)
        {
            Journey journey = await journeyService.GetByIdAsync(id);

            if (journey == null)
            {
                TempData.AddErrorMessage(WebConstants.ErrorTryAgain);
                return(NotFound());
            }

            foreach (UserJourney passenger in journey.Passengers)
            {
                this.SendEmailToPassenger(journey, passenger.User.Email, EmailConstants.RemoveSubject, EmailConstants.RemoveBody);
            }

            return(await base.Delete(id));
        }
Example #2
0
        public async Task <JsonResult> GetContacts(int journeyId)
        {
            User currentUser = await userManager.GetUserAsync(User);

            Journey journey = await journeyService.GetByIdAsync(journeyId);

            if (journey == null)
            {
                return(null);
            }

            // return all the passengers if the sender of the message is the driver of the journey
            if (journey.DriverId == currentUser.Id)
            {
                return(Json(mapper.Map <IEnumerable <User>, IEnumerable <UserChatViewModel> >(journey.Passengers.Select(p => p.User))));
            }
            else if (journey.Passengers.Any(p => p.UserId == currentUser.Id)) //return the driver only if the sender is one of the passengers
            {
                return(Json(mapper.Map <User, UserChatViewModel>(journey.Driver)));
            }

            return(null);
        }