public List <int> SaveServeRsvp(string token, SaveRsvpDto dto) { List <MailRow> mailRows = new List <MailRow>(); var templateId = GetRsvpTemplate(dto.SignUp); var opportunity = GetOpportunity(token, dto.OpportunityId, dto.OpportunityIds); var groupContact = _contactService.GetContactById(opportunity.GroupContactId); var toContact = _contactService.GetContactById(dto.ContactId); MpOpportunity previousOpportunity = null; try { var fromDate = GetTimeStamp(opportunity.ShiftStart); var toDate = GetTimeStamp(opportunity.ShiftEnd); var updatedEvents = GetUpdatedOpportunities(token, dto, (participant, e) => { mailRows.Add(new MailRow() { EventDate = e.EventStartDate.ToShortDateString(), Location = opportunity.Room, OpportunityName = opportunity.OpportunityName, ShiftTime = fromDate + " - " + toDate }); var response = CreateRsvp(token, dto.OpportunityId, dto.OpportunityIds, dto.SignUp, participant, e, groupContact); previousOpportunity = PreviousOpportunity(response, previousOpportunity); templateId = GetTemplateId(templateId, response); return(true); }); var table = SetupHTMLTable(mailRows).Build(); var mergeData = SetupMergeData(dto.ContactId, dto.OpportunityId, previousOpportunity, opportunity, dto.StartDateUnix.FromUnixTime(), dto.EndDateUnix.FromUnixTime(), groupContact, table); var communication = SetupCommunication(templateId, groupContact, toContact, mergeData); _communicationService.SendMessage(communication); return(updatedEvents); } catch (Exception e) { //var communication = SetupCommunication(templateId, groupContact, toContact); var table = SetupHTMLTable(mailRows).Build(); var communication = SetupCommunication(AppSetting("SignupToServeFailedMessage"), groupContact, toContact, new Dictionary <string, object> { { "Html_Table", table } }); _communicationService.SendMessage(communication); return(new List <int>()); } }
public IHttpActionResult SaveRsvp([FromBody] SaveRsvpDto saveRsvp) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message); var dataError = new ApiErrorDto("RSVP Data Invalid", new InvalidOperationException("Invalid RSVP Data" + errors)); throw new HttpResponseException(dataError.HttpResponseMessage); } //validate request if (saveRsvp.StartDateUnix <= 0) { var dateError = new ApiErrorDto("StartDate Invalid", new InvalidOperationException("Invalid Date")); throw new HttpResponseException(dateError.HttpResponseMessage); } return(Authorized(token => { var message = _messageFactory.CreateMessage(saveRsvp); _eventQueue.Send(message, MessageQueueTransactionType.None); // get updated events and return them var updatedEvents = new UpdatedEvents(); try { updatedEvents.EventIds.AddRange(_serveService.GetUpdatedOpportunities(token, saveRsvp)); } catch (Exception exception) { var apiError = new ApiErrorDto("Save RSVP Failed", exception); throw new HttpResponseException(apiError.HttpResponseMessage); } return Ok(updatedEvents); })); }
public List <int> GetUpdatedOpportunities(string token, SaveRsvpDto dto, Func <MpParticipant, MpEvent, bool> saveFunc = null) { var updatedEvents = new List <int>(); //get participant id for Contact var participant = _participantService.GetParticipant(dto.ContactId); //get events in range var events = GetEventsInRange(token, dto.EventTypeId, dto.StartDateUnix.FromUnixTime(), dto.EndDateUnix.FromUnixTime()); var increment = dto.AlternateWeeks ? 14 : 7; var sequenceDate = dto.StartDateUnix.FromUnixTime(); for (var i = 0; i < events.Count(); i++) { var @event = events[i]; sequenceDate = IncrementSequenceDate(@event, sequenceDate, increment); if (@event.EventStartDate.Date != sequenceDate.Date) { continue; } updatedEvents.Add(@event.EventId); if (saveFunc != null) { saveFunc(participant, @event); } sequenceDate = sequenceDate.AddDays(increment); } return(updatedEvents); }