コード例 #1
0
 void UpdateEvent(Event newEvent, DuplicateEventViewModel model)
 {
     newEvent.Name          = model.Name;
     newEvent.Description   = model.Description;
     newEvent.StartDateTime = model.StartDateTime;
     newEvent.EndDateTime   = model.EndDateTime;
 }
コード例 #2
0
        public async Task CopyEventPropertyValuesToTheNewEvent()
        {
            var duplicateEventModel = new DuplicateEventViewModel
            {
                Id            = EventToDuplicateId,
                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(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.False(sut.IsLimitVolunteers);
            Assert.True(sut.IsAllowWaitList);
        }
コード例 #3
0
        public async Task <IActionResult> Duplicate(DuplicateEventViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }

            if (!viewModel.UserIsOrgAdmin)
            {
                return(Unauthorized());
            }

            var existingEvent = await _mediator.SendAsync(new EventEditQuery { EventId = viewModel.Id });

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

            var newEvent = BuildNewEventDetailsModel(existingEvent, viewModel);

            //mgmccarthy: why are we validating here? We don't need to validate as the event that is being duplicated was already validated before it was created
            var errors = _eventEditViewModelValidator.Validate(newEvent, campaign);

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

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

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

            return(View(viewModel));
        }
コード例 #4
0
        public async Task <IActionResult> Duplicate(DuplicateEventViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

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

            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 }));
            }

            return(View(model));
        }
コード例 #5
0
        async Task <int> DuplicateEvent(DuplicateEventViewModel duplicateEventModel)
        {
            var command = new DuplicateEventCommand {
                DuplicateEventModel = duplicateEventModel
            };
            var handler = new DuplicateEventCommandHandler(Context);

            return(await handler.Handle(command));
        }
コード例 #6
0
        void UpdateTasks(Event @event, DuplicateEventViewModel 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);
            }
        }
コード例 #7
0
        static void UpdateVolunteerTasks(Event @event, DuplicateEventViewModel updateModel)
        {
            foreach (var volunteerTask in @event.VolunteerTasks)
            {
                var existingStartDateTime = volunteerTask.StartDateTime;
                var existingEndDateTime   = volunteerTask.EndDateTime;

                volunteerTask.StartDateTime = updateModel.StartDateTime - (@event.StartDateTime - volunteerTask.StartDateTime);
                volunteerTask.EndDateTime   = volunteerTask.StartDateTime + (existingEndDateTime - existingStartDateTime);
            }
        }
コード例 #8
0
        public async Task MaintainOffsetBetweenTaskStartTimeAndEventStartTimeInNewTask()
        {
            var duplicateEventModel = new DuplicateEventViewModel
            {
                Id            = EventToDuplicateId,
                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.VolunteerTasks.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);
        }
コード例 #9
0
        public async Task CreateNewTasksWithoutCopyingAssignedVolunteers()
        {
            var duplicateEventModel = new DuplicateEventViewModel
            {
                Id            = EventToDuplicateId,
                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.VolunteerTasks.OrderBy(t => t.StartDateTime).ToList();

            Assert.Empty(sut[0].AssignedVolunteers);
            Assert.Empty(sut[1].AssignedVolunteers);
        }
コード例 #10
0
        public async Task CreateNewTasksWithoutCopyingAssignedVolunteers()
        {
            var duplicateEventModel = new DuplicateEventViewModel()
            {
                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());
        }
コード例 #11
0
        public async Task MaintainTaskDurationInNewTask()
        {
            var duplicateEventModel = new DuplicateEventViewModel()
            {
                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);
        }
コード例 #12
0
 private static EventEditViewModel BuildNewEventDetailsModel(EventEditViewModel existingEvent, DuplicateEventViewModel newEventDetails)
 {
     existingEvent.Id            = 0;
     existingEvent.Name          = newEventDetails.Name;
     existingEvent.Description   = newEventDetails.Description;
     existingEvent.StartDateTime = newEventDetails.StartDateTime;
     existingEvent.EndDateTime   = newEventDetails.EndDateTime;
     return(existingEvent);
 }
コード例 #13
0
 void ApplyUpdates(Event @event, DuplicateEventViewModel updateModel)
 {
     UpdateTasks(@event, updateModel);
     UpdateEvent(@event, updateModel);
 }
コード例 #14
0
 private void ApplyUpdates(Event @event, DuplicateEventViewModel updateModel)
 {
     UpdateVolunteerTasks(@event, updateModel);
     UpdateEvent(@event, updateModel);
 }