void UpdateEvent(Event newEvent, DuplicateEventViewModel model) { newEvent.Name = model.Name; newEvent.Description = model.Description; newEvent.StartDateTime = model.StartDateTime; newEvent.EndDateTime = model.EndDateTime; }
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); }
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)); }
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)); }
async Task <int> DuplicateEvent(DuplicateEventViewModel duplicateEventModel) { var command = new DuplicateEventCommand { DuplicateEventModel = duplicateEventModel }; var handler = new DuplicateEventCommandHandler(Context); return(await handler.Handle(command)); }
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); } }
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); } }
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); }
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); }
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()); }
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); }
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); }
void ApplyUpdates(Event @event, DuplicateEventViewModel updateModel) { UpdateTasks(@event, updateModel); UpdateEvent(@event, updateModel); }
private void ApplyUpdates(Event @event, DuplicateEventViewModel updateModel) { UpdateVolunteerTasks(@event, updateModel); UpdateEvent(@event, updateModel); }