public async Task<IActionResult> Assign(int id, List<TaskViewModel> tasks)
        {
            var currentUser = await _userManager.GetCurrentUser(Context);

            if (currentUser == null)
            {
                return new HttpUnauthorizedResult();
            }

            if (!await UserIsTenantAdminOfActivity(currentUser, id))
            {
                return new HttpUnauthorizedResult();
            }

            var updates = tasks.ToModel(_dataAccess).ToList();
            //TODO: Replacement for API like Tasks.UpdateRange(updates);
            foreach (var item in updates)
            {
                await _dataAccess.UpdateTask(item);
            }
            return RedirectToRoute(new { controller = "Activity", Area = "Admin", action = "Details", id = id });
        }
Example #2
0
 public BookResponse Book(string authenticationId, string sessionId, AirItinerary airItinerary, List<Passenger> passengers,
                          List<Charge> charges)
 {
     IFlightProvider flightProvider = FlightProviderFactory.GetFlightProvider();
     var response = new BookResponse();
     var authenticationProvider = AuthenticationProviderFactory.GetAuthenticationProvider();
     var accountId = authenticationProvider.GetAccountId(authenticationId);
     var accountProvider = AccountProviderFactory.GetAccountProvider();
     ISessionProvider sessionProvider = SessionProviderFactory.GetSessionProvider();
     string errorMessage;
     SessionData sessionData = sessionProvider.GetSession(authenticationId, sessionId, out errorMessage);
     if (!string.IsNullOrEmpty(accountId) && airItinerary != null && charges != null && charges.Count > 0)
     {
         try
         {
             Booking booking;
             errorMessage = string.Empty;
             if (flightProvider.Book(sessionData.Request.RequestId, airItinerary.ToModel(), passengers.ToModel(), charges.ToModel(),
                                     accountProvider.GetAccount(accountId), out errorMessage, out booking) && string.IsNullOrEmpty(errorMessage))
             {
                 response.IsSuccess = true;
                 response.Charges = charges;
                 response.Itinerary = airItinerary;
                 response.Passengers = passengers;
                 response.Pnr = booking.FlightBookings[0].Pnr;
                 response.TicketNumbers = booking.TicketNumbers;
             }
             else
             {
                 response.IsSuccess = false;
                 response.ErrorMessage = errorMessage;
             }
         }
         catch (Exception exception)
         {
             response.IsSuccess = false;
             response.ErrorMessage = "Something is not quite right here. Please try again later.";
             Logger.LogException(exception, Source, "Book", Severity.Critical);
         }
     }
     if (!response.IsSuccess)
     {
         IEmailProvider emailProvider = EmailProviderFactory.GetEmailProvider();
         emailProvider.SendBookingFailureNotificationEmail(sessionData.Request.RequestId, sessionId,
                                                           response.ErrorMessage);
     }
     return response;
 }
Example #3
0
 public PriceResponse Price(string sessionId, AirItinerary airItinerary, List<Charge> charges)
 {
     IFlightProvider flightProvider = FlightProviderFactory.GetFlightProvider();
     var response = new PriceResponse();
     if (airItinerary != null)
     {
         try
         {
             string errorMessage;
             decimal chargeAmount;
             if (flightProvider.Price(airItinerary.ToModel(), charges.ToModel(), out errorMessage,
                                      out chargeAmount))
             {
                 response.IsSuccess = true;
                 response.DisplayChargeAmount = chargeAmount;
                 response.Currency = airItinerary.AirFare.Currency;
                 response.PaymentUrl = "testURL";
                 response.PaymentPostData = "testData";
             }
             else
             {
                 response.IsSuccess = false;
                 response.ErrorMessage = errorMessage;
             }
         }
         catch (Exception exception)
         {
             response.IsSuccess = false;
             response.ErrorMessage = "Something is not quite right here. Please try again later.";
             Logger.LogException(exception, Source, "Price", Severity.Critical);
         }
     }
     return response;
 }
        public async Task<IActionResult> Assign(int id, List<TaskViewModel> tasks)
        {
            if (!UserIsTenantAdminOfActivity(id))
            {
                return new HttpUnauthorizedResult();
            }

            var updates = tasks.ToModel(_dataAccess).ToList();
            //TODO: Replacement for API like Tasks.UpdateRange(updates);
            foreach (var item in updates)
            {
                await _dataAccess.UpdateTaskAsync(item);
            }

            // send all notifications to the queue
            var smsRecipients = new List<string>();
            var emailRecipients = new List<string>();

            foreach (var allReadyTask in updates)
            {
                // get all confirmed contact points for the broadcast
                smsRecipients.AddRange(allReadyTask.AssignedVolunteers.Where(u => u.User.PhoneNumberConfirmed).Select(v => v.User.PhoneNumber));
                emailRecipients.AddRange(allReadyTask.AssignedVolunteers.Where(u => u.User.EmailConfirmed).Select(v => v.User.Email));
            }

            var command = new NotifyVolunteersCommand
            {
                // todo: what information do we add about the task?
                // todo: should we use a template from the email service provider?
                // todo: what about non-English volunteers?
                ViewModel = new NotifyVolunteersViewModel
                {
                    SmsMessage = "You've been assigned a task from AllReady.",
                    SmsRecipients = smsRecipients,
                    EmailMessage = "You've been assigned a task from AllReady.",
                    EmailRecipients = emailRecipients,
                    Subject = "You've been assigned a task from AllReady."
                }
            };

            _bus.Send(command);

            return RedirectToRoute(new { controller = "Activity", Area = "Admin", action = "Details", id = id });
        }