public int AddEventSeries(EventSeries eventSeries)
 {
     using (var db = new CalendarDbContext())
     {
         var entity = db.EventSeries.Add(eventSeries);
         db.SaveChanges();
         return(entity.Entity.Id);
     }
 }
 public EventSeries UpdateEventSeries(EventSeries editedEventSeries)
 {
     using (var db = new CalendarDbContext())
     {
         var addedEntity = db.EventSeries.Update(editedEventSeries);
         db.SaveChanges();
         return(addedEntity.Entity);
     }
 }
示例#3
0
        public void Given_Valid_Values_EventSeries_Is_Valid()
        {
            // Arrange
            string title       = "New Event Series";
            string description = "This is a new Event Series";

            // Act
            var es = new EventSeries(title, description);

            // Assert
            Assert.Equal("New Event Series", es.Title);
            Assert.Equal("This is a new Event Series", es.Description);
        }
 public EventSeriesEditViewModel(EventSeries es)
 {
     Id          = es.Id;
     Title       = es.Title;
     Description = es.Description;
     if (es.Events == null)
     {
         throw new ArgumentNullException("Cannot create viewmodel from EventSeries object with null Events collection.", nameof(es.Events));
     }
     else
     {
         InitializeEventList(es.Events);
     }
 }
示例#5
0
        public void Can_Update_Title()
        {
            // Arrange
            string title       = "New Event Series";
            string description = "This is a new Event Series";
            var    es          = new EventSeries(title, description);

            Assert.Equal("New Event Series", es.Title);

            // Act
            es.UpdateTitle("Updated Title");

            // Assert
            Assert.Equal("Updated Title", es.Title);
        }
示例#6
0
        public void Can_Update_Description()
        {
            // Arrange
            string title       = "New Event Series";
            string description = "This is a new Event Series";
            var    es          = new EventSeries(title, description);

            Assert.Equal("This is a new Event Series", es.Description);

            // Act
            es.UpdateDescription("This is an updated description.");

            // Assert
            Assert.Equal("This is an updated description.", es.Description);
        }
        public async Task <IActionResult> Delete(int?id, string returnUrl)
        {
            if (id == null || !EventSeriesExists((int)id))
            {
                return(NotFound());
            }
            EventSeries es = await _eventService.EventSeries.GetEventSeriesWithEventsAndRegistrationsAsync((int)id);

            EventSeriesEditViewModel vm = new EventSeriesEditViewModel(es);

            ViewData["ActiveMenu"] = "Admin";
            ViewData["ActiveLink"] = "DeleteEventSeries";
            ViewData["Title"]      = "Delete Event Series?";
            ViewBag.ReturnUrl      = returnUrl;
            return(View(vm));
        }
 public EventSeriesIndexViewModelEventSeriesItem(EventSeries e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("Cannot construct item from null EventSeries parameter", nameof(e));
     }
     else if (e.Events == null)
     {
         throw new ArgumentNullException("Cannot construct item from Event with null Events Collection", nameof(e.Events));
     }
     else
     {
         EventSeriesId         = e.Id;
         EventSeriesTitle      = e.Title;
         EventSeriesEventCount = e?.Events?.Count() ?? 0;
     }
 }
        /// <summary>
        /// Handles the request to insert or update the <see cref="EventSeries"></see>
        /// </summary>
        /// <param name="request">The command</param>
        /// <param name="cancellationToken">The cancellationToken</param>
        /// <returns>A <see cref="Task"> containing the Integer Id of the upserted entity.</see></returns>
        /// <exception cref="ValidationException">Throw when the "Title" property of the request parameter is in use by another <see cref="EventSeries"></see></exception>
        /// <exception cref="NotFoundException">Throw when the "Id" property of the request parameter is present, but does not match the Id of any existing <see cref="EventSeries"></see></exception>
        public async Task <int> Handle(UpsertEventSeriesesCommand request, CancellationToken cancellationToken)
        {
            EventSeries entity;

            if (request.Id.HasValue)
            {
                // we are updating an existing Event Series
                var titleIsTaken = _context.EventSeries.Any(x => x.Title == request.Title && x.Id != request.Id);
                if (titleIsTaken)
                {
                    throw new ValidationException(new List <ValidationFailure>()
                    {
                        new ValidationFailure(nameof(EventSeries.Title), $"The title \"{request.Title}\" is already in use.")
                    });
                }
                entity = await _context.EventSeries.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(EventSeries), request.Id);
                }
                entity.UpdateTitle(request.Title);
                entity.UpdateDescription(request.Description);
            }
            else
            {
                // we are creating a new Event Series
                var titleIsTaken = _context.EventSeries.Any(x => x.Title == request.Title);
                if (titleIsTaken)
                {
                    throw new ValidationException(new List <ValidationFailure>()
                    {
                        new ValidationFailure(nameof(EventSeries.Title), $"The title \"{request.Title}\" is already in use.")
                    });
                }
                entity = new EventSeries(request.Title, request.Description);
                await _context.EventSeries.AddAsync(entity);
            }
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
示例#10
0
 public bool CreateEventSeries(string title, string description, out string response)
 {
     if (EventSeries.ValueIsInUseByIdForExpression(x => x.Title == title))
     {
         response = $"An Event Series with the name {title} already exists.";
         return(false);
     }
     try
     {
         EventSeries toAdd = new EventSeries(title, description);
         EventSeries.Add(toAdd);
         Complete();
         response = "Event Series added";
         return(true);
     }
     catch (Exception ex)
     {
         response = ex.Message;
         return(false);
     }
 }
示例#11
0
 public bool DeleteEventSeries(int id, out string response)
 {
     try
     {
         EventSeries toRemove = EventSeries.Get(id);
         EventSeries.Remove(toRemove);
         List <Event> eventsForRemovedSeries = Events.Find(x => x.EventSeriesId == id).ToList();
         foreach (Event e in eventsForRemovedSeries)
         {
             e.RemoveEventFromSeries();
         }
         Complete();
         response = $"Event Series removed, {eventsForRemovedSeries} Events reassigned.";
         return(true);
     }
     catch (Exception ex)
     {
         response = ex.Message;
         return(false);
     }
 }
示例#12
0
        public bool UpdateEventSeries(int eventSeriesId, string title, string description, out string response)
        {
            EventSeries toUpdate = EventSeries.Get(eventSeriesId);

            if (EventSeries.ValueIsInUseByIdForExpression(x => x.Title == title && x.Id != eventSeriesId))
            {
                response = $"Cannot update Event Series: Title is in use by another Series.";
                return(false);
            }
            try
            {
                toUpdate.UpdateTitle(title);
                toUpdate.UpdateDescription(description);
                Complete();
                response = "Event Series updated.";
                return(true);
            }
            catch (Exception ex)
            {
                response = ex.Message;
                return(false);
            }
        }
        public void EventSeriesWorking()
        {
            //Prepare
            var es = new EventSeries()
            {
                Description = "TestDescription",
                SeriesCode = "TestCode",
                SeriesStart = DateTime.Now.Subtract(TimeSpan.FromDays(1)),
                SeriesEnd = DateTime.Now
            };

            var locs = new[]
            {
                new Localization(){ Longitude = 10.0, Altitude = 1.0, Latitude = 30.0},
                new Localization(){ Longitude = 12.0, Altitude = 1.0, Latitude = 33.0},
                new Localization(){ Longitude = 4.0, Altitude = 1.0, Latitude = 3.0},
            };

            //Execute
            var id = _target.InsertEventSeries(es, locs, TestResources.Credentials);

            //Assert
            //Nothing to assert
        }
示例#14
0
        /// <summary>
        /// Handles the request to insert the <see cref="Event"></see>
        /// </summary>
        /// <param name="request">The command</param>
        /// <param name="cancellationToken">The cancellationToken</param>
        /// <returns>A <see cref="Task"> containing the Integer Id of the newly inserted entity.</see></returns>
        /// <exception cref="ValidationException">
        /// Throw when:
        /// <list type="bullet">
        /// <item><description>the EventTypeId property of the request parameter does not match any existing <see cref="EventType"></see></description></item>
        /// <item><description>the EventSeriesId property of the request parameter is present but does not match any existing <see cref="EventSeries"></see></description></item>
        /// <item><description>one of the Dates used to construct the <see cref="EventDates"></see> value object caused an error in that object's constructor.</description></item>
        /// <item><description>an error was thrown in the constructor of the <see cref="EventRegistrationRules"></see> value object, likely because of a bad registration count value.</description></item>
        /// <item><description>an error was thrown in the constructor of the <see cref="Event"></see> entity object, likely because of a bad parameter that was not caught by validation.</description></item>
        /// </list>
        /// </exception>
        public async Task <int> Handle(CreateEventCommand request, CancellationToken cancellationToken)
        {
            // Attempt to find the Event Type that matches request.EventTypeId
            var type = _context.EventTypes.Find(request.EventTypeId);

            if (type == null)
            {
                // throw if no EventType was found
                throw new ValidationException(new List <ValidationFailure>()
                {
                    new ValidationFailure(nameof(Event.EventTypeId), $"No Event Type with Id: \"{request.EventTypeId}\" was found.")
                });
            }
            // Attempt to find the Event Series that matches request.EventSeriesId
            EventSeries series = null;

            if (request.EventSeriesId.HasValue) // request.EventSeriesId is an optional parameter, so check if it is present
            {
                // Attempt to locate the matching series
                series = _context.EventSeries.Find(request.EventSeriesId);
                if (series == null)
                {
                    // throw if no matching series was found
                    throw new ValidationException(new List <ValidationFailure>()
                    {
                        new ValidationFailure(nameof(Event.EventSeriesId), $"No Event Series with Id: \"{request.EventSeriesId}\" was found.")
                    });
                }
            }
            try
            {
                Event entity = new Event(
                    request.Title,
                    request.Description,
                    request.EventTypeId,
                    request.EventSeriesId,
                    request.StartDate,
                    request.EndDate,
                    request.RegStartDate,
                    request.RegEndDate,
                    request.MaxRegsCount,
                    request.MinRegsCount,
                    request.MaxStandbyCount,
                    request.Street,
                    request.Suite,
                    request.City,
                    request.State,
                    request.Zip
                    );
                await _context.Events.AddAsync(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(entity.Id);
            }
            catch (Exception e)
            {
                // throw if the Event constructor threw an error, which is likely because a bad parameter made it through validation
                throw new ValidationException(new List <ValidationFailure>()
                {
                    new ValidationFailure(nameof(Event), e.Message)
                });
            }
        }
 internal static void OnMaterialized(EventSeries es)
 {
     es.StartDateUTC = EntityHelper.ForceUTC(es.StartDateUTC);
     es.EndDateUTC = EntityHelper.ForceUTC(es.EndDateUTC);
 }
 internal static void BeforeSave(EventSeries es)
 {
     es.StartDateUTC = EntityHelper.ForceLocal(es.StartDateUTC);
     es.EndDateUTC = EntityHelper.ForceLocal(es.EndDateUTC);
 }
示例#17
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);
            }
        }
示例#18
0
 public EventSeriesAddViewModel(EventSeries es)
 {
     Id          = es.Id;
     Title       = es.Title;
     Description = es.Description;
 }
示例#19
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);
            }
        }