Exemplo n.º 1
0
        public int CreateEventGroup(MpEventGroup eventGroup, string token = "")
        {
            if (token == "")
            {
                token = ApiLogin();
            }
            var groupDictionary = new Dictionary <string, object>
            {
                { "Event_ID", eventGroup.EventId },
                { "Group_ID", eventGroup.GroupId },
                { "Room_ID", eventGroup.RoomId },
                { "Domain_ID", 1 },
                { "Closed", eventGroup.Closed },
                { "Event_Room_ID", eventGroup.EventRoomId }
            };

            try
            {
                return(_ministryPlatformService.CreateRecord(_eventGroupsPageId, groupDictionary, token, true));
            }
            catch (Exception e)
            {
                var msg = string.Format("Error creating Event Group, eventGroup: {0}", eventGroup);
                _logger.Error(msg, e);
                throw (new ApplicationException(msg, e));
            }
        }
Exemplo n.º 2
0
        public int AddEventGroup(int eventId, int groupId, string token)
        {
            var eventGroup = new MpEventGroup
            {
                EventId  = eventId,
                GroupId  = groupId,
                DomainId = 1
            };

            return(_eventService.CreateEventGroup(eventGroup));
        }
Exemplo n.º 3
0
        public void UpdateEventGroup(MpEventGroup eventGroup, string token)
        {
            var groupDictionary = new Dictionary <string, object>
            {
                { "Event_ID", eventGroup.EventId },
                { "Group_ID", eventGroup.GroupId },
                { "Room_ID", eventGroup.RoomId },
                { "Domain_ID", eventGroup.DomainId },
                { "Closed", eventGroup.Closed },
                { "Event_Room_ID", eventGroup.EventRoomId }
            };

            try
            {
                _ministryPlatformService.UpdateRecord(_eventGroupsPageViewId, groupDictionary, token);
            }
            catch (Exception e)
            {
                var msg = string.Format("Error updating Event Group, eventGroup: {0}", eventGroup);
                _logger.Error(msg, e);
                throw (new ApplicationException(msg, e));
            }
        }
Exemplo n.º 4
0
        // TODO: Should we merge childcareRequestId into the childcareRequestDto?
        public void ApproveChildcareRequest(int childcareRequestId, ChildcareRequestDto childcareRequest, string token)
        {
            try
            {
                var request          = GetChildcareRequestForReview(childcareRequestId, token);
                var datesFromRequest = _childcareRequestService.GetChildcareRequestDates(childcareRequestId);
                var requestedDates   = childcareRequest.DatesList.Select(date => GetChildcareDateFromList(datesFromRequest, date)).ToList();
                if (requestedDates.Count == 0)
                {
                    throw new ChildcareDatesMissingException(childcareRequestId);
                }
                var events = _childcareRequestService.FindChildcareEvents(childcareRequestId, requestedDates, request);

                var childcareEvents = GetChildcareEventsfortheDates(events, requestedDates, request);
                var missingDates    = requestedDates.Where(childcareRequestDate => !childcareEvents.ContainsKey(childcareRequestDate.ChildcareRequestDateId)).ToList();
                if (missingDates.Count > 0)
                {
                    var dateList = missingDates.Aggregate("", (current, date) => current + ", " + date.RequestDate.ToShortDateString());
                    _logger.Debug("Missing events for dates: ${dateList}");
                    var dateMap = missingDates.Select(c => c.RequestDate).ToList();
                    throw new EventMissingException(dateMap);
                }

                //set the approved column for dates to true
                foreach (var ccareDates in requestedDates)
                {
                    _childcareRequestService.DecisionChildcareRequestDate(ccareDates.ChildcareRequestDateId, true);
                    var eventId    = childcareEvents.Where((ev) => ev.Key == ccareDates.ChildcareRequestDateId).Select((ev) => ev.Value).SingleOrDefault();
                    var eventGroup = new MpEventGroup()
                    {
                        Closed = false, Created = true, EventId = eventId, GroupId = request.GroupId
                    };
                    var currentGroups = _eventService.GetGroupsForEvent(eventId).Select((g) => g.GroupId).ToList();
                    if (!currentGroups.Contains(request.GroupId))
                    {
                        _eventService.CreateEventGroup(eventGroup, token);
                    }
                }

                var requestStatusId = GetApprovalStatus(datesFromRequest, requestedDates);
                _childcareRequestService.DecisionChildcareRequest(childcareRequestId, requestStatusId, childcareRequest.ToMPChildcareRequest());
                var templateId = GetApprovalEmailTemplate(requestStatusId);
                SendChildcareRequestDecisionNotification(childcareRequestId, requestedDates, childcareRequest, templateId, token);
            }
            catch (EventMissingException ex)
            {
                throw;
            }
            catch (ChildcareDatesMissingException ex)
            {
                throw;
            }
            catch (DuplicateChildcareEventsException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Update Request failed"), ex);
                throw new Exception("Approve Childcare failed", ex);
            }
        }
Exemplo n.º 5
0
 public void DeleteEventGroup(MpEventGroup eventGroup, string token)
 {
     _ministryPlatformService.DeleteRecord(_eventGroupsPageId, eventGroup.EventGroupId, null, token);
 }