Ejemplo n.º 1
0
 public bool UpdateEventType(int eventTypeId, string eventTypeName, out string response)
 {
     if (EventTypes.ValueIsInUseByIdForExpression(x => x.EventTypeName == eventTypeName && x.Id != eventTypeId))
     {
         response = $"An Event Type named {eventTypeName} already exists.";
         return(false);
     }
     try
     {
         EventType toUpdate = EventTypes.Get(eventTypeId);
         toUpdate.UpdateEventTypeName(eventTypeName);
         Complete();
         response = "Event Type added.";
         return(true);
     }
     catch (Exception ex)
     {
         response = ex.Message;
         return(false);
     }
 }
Ejemplo n.º 2
0
        public bool CreateEvent(
            out string response,
            int eventTypeId,
            int ownerUserId,
            string title,
            string description,
            DateTime startDate,
            DateTime endDate,
            DateTime registrationOpenDate,
            DateTime?registrationClosedDate,
            string locationLine1,
            string locationLine2,
            string locationCity,
            string locationState,
            string locationZip,
            int eventSeriesId              = 0,
            int maxRegistrations           = 1,
            int minRegistrations           = 0,
            bool allowStandbyRegistrations = false,
            int maxStandbyRegistrations    = 0,
            string fundCenter              = ""
            )
        {
            User creator = null;

            if (ownerUserId == 0)
            {
                creator = _currentUser;
            }
            else
            {
                creator = Users.Get(ownerUserId);
            }
            EventType   eventType   = EventTypes.Get(eventTypeId);
            EventSeries eventSeries = null;

            if (eventSeriesId != 0)
            {
                eventSeries = EventSeries.Get(eventSeriesId);
            }
            Address location = Address.Create(locationLine1, locationLine2, locationCity, locationState, locationZip);

            try
            {
                Event eventToAdd = new Event(
                    eventType,
                    location,
                    creator,
                    eventSeries,
                    title,
                    description,
                    startDate,
                    endDate,
                    registrationOpenDate,
                    registrationClosedDate,
                    maxRegistrations,
                    minRegistrations,
                    allowStandbyRegistrations,
                    maxStandbyRegistrations,
                    fundCenter
                    );
                Events.Add(eventToAdd);
                Complete();
                response = "Event Added";
                return(true);
            }
            catch (Exception e)
            {
                response = e.Message;
                return(false);
            }
        }
Ejemplo n.º 3
0
        public bool UpdateEvent(
            out string response,
            int eventId,
            int eventTypeId,
            int ownerUserId,
            string title,
            string description,
            DateTime startDate,
            DateTime endDate,
            DateTime registrationOpenDate,
            DateTime?registrationClosedDate,
            string locationLine1,
            string locationLine2,
            string locationCity,
            string locationState,
            string locationZip,
            int eventSeriesId              = 0,
            int maxRegistrations           = 1,
            int minRegistrations           = 0,
            bool allowStandbyRegistrations = false,
            int maxStandbyRegistrations    = 0,
            string fundCenter              = ""
            )
        {
            Event e = Events.Get(eventId);

            if (e == null)
            {
                throw new Exception($"No event with id {eventId} was found.");
            }
            try
            {
                if (e.Title != title)
                {
                    e.UpdateTitle(title);
                }
                if (e.Description != description)
                {
                    e.UpdateDescription(description);
                }
                if (e.FundCenter != fundCenter)
                {
                    e.UpdateFundCenter(fundCenter);
                }
                if (e.StartDate != startDate && e.EndDate != endDate)
                {
                    e.UpdateEventDates(startDate, endDate);
                }
                else if (e.StartDate != startDate && e.EndDate == endDate)
                {
                    e.UpdateEventDates(startDate, null);
                }
                else if (e.StartDate == startDate && e.EndDate != endDate)
                {
                    e.UpdateEventDates(null, endDate);
                }

                if (e.RegistrationOpenDate != registrationOpenDate && e.RegistrationClosedDate != registrationClosedDate)
                {
                    e.UpdateRegistrationPeriodDates(registrationOpenDate, registrationClosedDate);
                }
                else if (e.RegistrationOpenDate != registrationOpenDate && e.RegistrationClosedDate == registrationClosedDate)
                {
                    e.UpdateRegistrationPeriodDates(registrationOpenDate, null);
                }
                else if (e.RegistrationOpenDate == registrationOpenDate && e.RegistrationClosedDate != registrationClosedDate)
                {
                    e.UpdateRegistrationPeriodDates(null, registrationClosedDate);
                }
                if (e.MinimumRegistrationsCount != minRegistrations)
                {
                    e.UpdateMinimumRegistrationRequiredCount((uint)minRegistrations);
                }
                if (e.MaximumRegistrationsCount != maxRegistrations)
                {
                    e.UpdateMaximumRegistrationsAllowedCount((uint)maxRegistrations);
                }


                if (allowStandbyRegistrations == false)
                {
                    e.PreventStandByRegistrations();
                    // TODO: EventService/UpdateEvent: Handle existing standby registrations when true => false
                }
                else
                {
                    e.AllowStandByRegistrations((uint)maxStandbyRegistrations);
                }
                // TODO: EventService/UpdateEvent: Handle null location?
                Address newLocation = Address.Create(locationLine1, locationLine2, locationCity, locationState, locationZip);
                if (e.AddressFactory != newLocation)
                {
                    e.UpdateEventLocation(newLocation);
                }
                if (e.EventTypeId != eventTypeId)
                {
                    e.UpdateEventType(EventTypes.Get(eventTypeId));
                }
                if (eventSeriesId != 0 && e.EventSeriesId != eventSeriesId)
                {
                    e.AddEventToSeries(EventSeries.Get(eventSeriesId));
                }
                else if (eventSeriesId == 0 && e.EventSeriesId != null)
                {
                    e.RemoveEventFromSeries();
                }
                if (e.EventTypeId != eventTypeId)
                {
                    e.UpdateEventType(EventTypes.Get(eventTypeId));
                }
                if (ownerUserId != 0 && e.OwnerId != ownerUserId)
                {
                    e.UpdateOwner(Users.Get(ownerUserId));
                }
                Complete();
                response = "Event Updated";
                return(true);
            }
            catch (Exception ex)
            {
                response = ex.Message;
                return(false);
            }
        }