public async Task CopyEventPropertyValuesToTheNewEvent()
        {
            var duplicateEventModel = new DuplicateEventModel()
            {
                Id            = EVENT_TO_DUPLICATE_ID,
                Name          = "Name",
                Description   = "Description",
                StartDateTime = new DateTimeOffset(2016, 1, 1, 0, 0, 0, new TimeSpan()),
                EndDateTime   = new DateTimeOffset(2016, 1, 31, 0, 0, 0, new TimeSpan())
            };

            var eventId = await DuplicateEvent(duplicateEventModel);

            var sut = await GetEvent(eventId);

            Assert.Equal(1, sut.CampaignId);
            Assert.Equal(1, sut.Campaign.Id);
            Assert.Equal("Name", sut.Name);
            Assert.Equal("Description", sut.Description);
            Assert.Equal(EventType.Itinerary, sut.EventType);
            Assert.Equal(10, sut.NumberOfVolunteersRequired);
            Assert.Equal(new DateTimeOffset(2016, 1, 1, 0, 0, 0, new TimeSpan()), sut.StartDateTime);
            Assert.Equal(new DateTimeOffset(2016, 1, 31, 0, 0, 0, new TimeSpan()), sut.EndDateTime);
            Assert.Equal("Organizer", sut.Organizer.Id);
            Assert.Equal("ImageUrl", sut.ImageUrl);
            Assert.Equal(false, sut.IsLimitVolunteers);
            Assert.Equal(true, sut.IsAllowWaitList);
        }
Ejemplo n.º 2
0
 void UpdateEvent(Event newEvent, DuplicateEventModel model)
 {
     newEvent.Name          = model.Name;
     newEvent.Description   = model.Description;
     newEvent.StartDateTime = model.StartDateTime;
     newEvent.EndDateTime   = model.EndDateTime;
 }
        public async Task CopyEventPropertyValuesToTheNewEvent()
        {
            var duplicateEventModel = new DuplicateEventModel()
            {
                Id = EVENT_TO_DUPLICATE_ID,
                Name = "Name",
                Description = "Description",
                StartDateTime = new DateTimeOffset(2016, 1, 1, 0, 0, 0, new TimeSpan()),
                EndDateTime = new DateTimeOffset(2016, 1, 31, 0, 0, 0, new TimeSpan())
            };

            var eventId = await DuplicateEvent(duplicateEventModel);
            var sut = await GetEvent(eventId);

            Assert.Equal(1, sut.CampaignId);
            Assert.Equal(1, sut.Campaign.Id);
            Assert.Equal("Name", sut.Name);
            Assert.Equal("Description", sut.Description);
            Assert.Equal(EventType.Itinerary, sut.EventType);
            Assert.Equal(10, sut.NumberOfVolunteersRequired);
            Assert.Equal(new DateTimeOffset(2016, 1, 1, 0, 0, 0, new TimeSpan()), sut.StartDateTime);
            Assert.Equal(new DateTimeOffset(2016, 1, 31, 0, 0, 0, new TimeSpan()), sut.EndDateTime);
            Assert.Equal("Organizer", sut.Organizer.Id);
            Assert.Equal("ImageUrl", sut.ImageUrl);
            Assert.Equal(false, sut.IsLimitVolunteers);
            Assert.Equal(true, sut.IsAllowWaitList);
        }
        public async Task <IActionResult> Duplicate(DuplicateEventModel model)
        {
            if (model == null)
            {
                return(HttpBadRequest());
            }

            var organizationId = _mediator.Send(new ManagingOrganizationIdByEventIdQuery {
                EventId = model.Id
            });

            if (!User.IsOrganizationAdmin(organizationId))
            {
                return(HttpUnauthorized());
            }

            var existingEvent = await _mediator.SendAsync(new EventDetailQuery { EventId = model.Id });

            var campaign = await _mediator.SendAsync(new CampaignSummaryQuery { CampaignId = existingEvent.CampaignId });

            var newEvent = buildNewEventDetailsModel(existingEvent, model);

            var errors = _eventDetailModelValidator.Validate(newEvent, campaign);

            errors.ForEach(e => ModelState.AddModelError(e.Key, e.Value));

            if (ModelState.IsValid)
            {
                var id = await _mediator.SendAsync(new DuplicateEventCommand { DuplicateEventModel = model });

                return(RedirectToAction(nameof(Details), new { area = "Admin", id = id }));
            }

            return(View(model));
        }
        async Task <int> DuplicateEvent(DuplicateEventModel duplicateEventModel)
        {
            var command = new DuplicateEventCommand()
            {
                DuplicateEventModel = duplicateEventModel
            };
            var handler = new DuplicateEventCommandHandler(Context);

            return(await handler.Handle(command));
        }
Ejemplo n.º 6
0
        void UpdateTasks(Event @event, DuplicateEventModel updateModel)
        {
            foreach (var task in @event.Tasks)
            {
                var existingStartDateTime = task.StartDateTime;
                var existingEndDateTime   = task.EndDateTime;

                task.StartDateTime = updateModel.StartDateTime - (@event.StartDateTime - task.StartDateTime);
                task.EndDateTime   = task.StartDateTime + (existingEndDateTime - existingStartDateTime);
            }
        }
        public async Task CreateNewTasksWithoutCopyingAssignedVolunteers()
        {
            var duplicateEventModel = new DuplicateEventModel()
            {
                Id            = EVENT_TO_DUPLICATE_ID,
                Name          = "Name",
                Description   = "Description",
                StartDateTime = new DateTimeOffset(2016, 2, 1, 0, 0, 0, new TimeSpan()),
                EndDateTime   = new DateTimeOffset(2016, 2, 28, 0, 0, 0, new TimeSpan())
            };

            var eventId = await DuplicateEvent(duplicateEventModel);

            var @event = await GetEvent(eventId);

            var sut = @event.Tasks.OrderBy(t => t.StartDateTime).ToList();

            Assert.Equal(0, sut[0].AssignedVolunteers.Count());
            Assert.Equal(0, sut[1].AssignedVolunteers.Count());
        }
        public async Task MaintainTaskDurationInNewTask()
        {
            var duplicateEventModel = new DuplicateEventModel()
            {
                Id            = EVENT_TO_DUPLICATE_ID,
                Name          = "Name",
                Description   = "Description",
                StartDateTime = new DateTimeOffset(2016, 2, 1, 0, 0, 0, new TimeSpan()),
                EndDateTime   = new DateTimeOffset(2016, 2, 28, 0, 0, 0, new TimeSpan())
            };

            var eventId = await DuplicateEvent(duplicateEventModel);

            var @event = await GetEvent(eventId);

            var sut = @event.Tasks.OrderBy(t => t.StartDateTime).ToList();

            Assert.Equal(new TimeSpan(8, 0, 0), sut[0].EndDateTime - sut[0].StartDateTime);
            Assert.Equal(new TimeSpan(6, 0, 0), sut[1].EndDateTime - sut[1].StartDateTime);
        }
Ejemplo n.º 9
0
 void ApplyUpdates(Event @event, DuplicateEventModel updateModel)
 {
     UpdateTasks(@event, updateModel);
     UpdateEvent(@event, updateModel);
 }
        public async Task MaintainOffsetBetweenTaskStartTimeAndEventStartTimeInNewTask()
        {
            var duplicateEventModel = new DuplicateEventModel()
            {
                Id = EVENT_TO_DUPLICATE_ID,
                Name = "Name",
                Description = "Description",
                StartDateTime = new DateTimeOffset(2016, 2, 1, 0, 0, 0, new TimeSpan()),
                EndDateTime = new DateTimeOffset(2016, 2, 28, 0, 0, 0, new TimeSpan())
            };

            var eventId = await DuplicateEvent(duplicateEventModel);
            var @event = await GetEvent(eventId);
            var sut = @event.Tasks.OrderBy(t => t.StartDateTime).ToList();

            Assert.Equal(new DateTimeOffset(2016, 2, 1, 9, 0, 0, new TimeSpan()), sut[0].StartDateTime);
            Assert.Equal(new DateTimeOffset(2016, 2, 2, 10, 0, 0, new TimeSpan()), sut[1].StartDateTime);
        }
 async Task<int> DuplicateEvent(DuplicateEventModel duplicateEventModel)
 {
     var command = new DuplicateEventCommand() { DuplicateEventModel = duplicateEventModel };
     var handler = new DuplicateEventCommandHandler(Context);
     return await handler.Handle(command);
 }
        public async Task CreateNewTasksWithoutCopyingAssignedVolunteers()
        {
            var duplicateEventModel = new DuplicateEventModel()
            {
                Id = EVENT_TO_DUPLICATE_ID,
                Name = "Name",
                Description = "Description",
                StartDateTime = new DateTimeOffset(2016, 2, 1, 0, 0, 0, new TimeSpan()),
                EndDateTime = new DateTimeOffset(2016, 2, 28, 0, 0, 0, new TimeSpan())
            };

            var eventId = await DuplicateEvent(duplicateEventModel);
            var @event = await GetEvent(eventId);
            var sut = @event.Tasks.OrderBy(t => t.StartDateTime).ToList();

            Assert.Equal(0, sut[0].AssignedVolunteers.Count());
            Assert.Equal(0, sut[1].AssignedVolunteers.Count());
        }
Ejemplo n.º 13
0
        private EventEditModel buildNewEventDetailsModel(EventEditModel existingEvent, DuplicateEventModel newEventDetails)
        {
            existingEvent.Id            = 0;
            existingEvent.Name          = newEventDetails.Name;
            existingEvent.Description   = newEventDetails.Description;
            existingEvent.StartDateTime = newEventDetails.StartDateTime;
            existingEvent.EndDateTime   = newEventDetails.EndDateTime;

            return(existingEvent);
        }
Ejemplo n.º 14
0
        private EventEditModel buildNewEventDetailsModel(EventEditModel existingEvent, DuplicateEventModel newEventDetails)
        {
            existingEvent.Id = 0;
            existingEvent.Name = newEventDetails.Name;
            existingEvent.Description = newEventDetails.Description;
            existingEvent.StartDateTime = newEventDetails.StartDateTime;
            existingEvent.EndDateTime = newEventDetails.EndDateTime;

            return existingEvent;
        }
Ejemplo n.º 15
0
        public async Task<IActionResult> Duplicate(DuplicateEventModel model)
        {
            if (model == null)
                return HttpBadRequest();

            var organizationId = _mediator.Send(new ManagingOrganizationIdByEventIdQuery { EventId = model.Id });
            if (!User.IsOrganizationAdmin(organizationId))
                return HttpUnauthorized();

            var existingEvent = await _mediator.SendAsync(new EventEditQuery() { EventId = model.Id });
            var campaign = await _mediator.SendAsync(new CampaignSummaryQuery { CampaignId = existingEvent.CampaignId });
            var newEvent = buildNewEventDetailsModel(existingEvent, model);

            var errors = _eventDetailModelValidator.Validate(newEvent, campaign);
            errors.ForEach(e => ModelState.AddModelError(e.Key, e.Value));

            if (ModelState.IsValid)
            {
                var id = await _mediator.SendAsync(new DuplicateEventCommand { DuplicateEventModel = model });

                return RedirectToAction(nameof(Details), new { area = "Admin", id = id });
            }

            return View(model);
        }