public EventViewModel(Event campaignEvent) { Id = campaignEvent.Id; if (campaignEvent.Campaign != null) { CampaignId = campaignEvent.Campaign.Id; CampaignName = campaignEvent.Campaign.Name; TimeZoneId = campaignEvent.Campaign.TimeZoneId; if (campaignEvent.Campaign.ManagingOrganization != null) { OrganizationId = campaignEvent.Campaign.ManagingOrganization.Id; OrganizationName = campaignEvent.Campaign.ManagingOrganization.Name; HasPrivacyPolicy = !string.IsNullOrEmpty(campaignEvent.Campaign.ManagingOrganization.PrivacyPolicy); } } Title = campaignEvent.Name; Description = campaignEvent.Description; EventType = campaignEvent.EventType; StartDateTime = campaignEvent.StartDateTime; EndDateTime = campaignEvent.EndDateTime; if (campaignEvent.Location != null) { Location = new LocationViewModel(campaignEvent.Location); } IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow; ImageUrl = campaignEvent.ImageUrl; //TODO Location Tasks = campaignEvent.Tasks != null ? new List<TaskViewModel>(campaignEvent.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime)) : new List<TaskViewModel>(); SignupModel = new EventSignupViewModel(); RequiredSkills = campaignEvent.RequiredSkills?.Select(acsk => acsk.Skill).ToList(); IsLimitVolunteers = campaignEvent.IsLimitVolunteers; IsAllowWaitList = campaignEvent.IsAllowWaitList; }
public EventViewModel(Event campaignEvent) { Id = campaignEvent.Id; if (campaignEvent.Campaign != null) { CampaignId = campaignEvent.Campaign.Id; CampaignName = campaignEvent.Campaign.Name; TimeZoneId = campaignEvent.Campaign.TimeZoneId; if (campaignEvent.Campaign.ManagingOrganization != null) { OrganizationId = campaignEvent.Campaign.ManagingOrganization.Id; OrganizationName = campaignEvent.Campaign.ManagingOrganization.Name; HasPrivacyPolicy = !string.IsNullOrEmpty(campaignEvent.Campaign.ManagingOrganization.PrivacyPolicy); } } Title = campaignEvent.Name; Description = campaignEvent.Description; EventType = campaignEvent.EventType; StartDateTime = campaignEvent.StartDateTime; EndDateTime = campaignEvent.EndDateTime; if (campaignEvent.Location != null) { Location = new LocationViewModel(campaignEvent.Location); } IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow; ImageUrl = campaignEvent.ImageUrl; //TODO Location Tasks = campaignEvent.Tasks != null ? new List <TaskViewModel>(campaignEvent.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime)) : new List <TaskViewModel>(); SignupModel = new EventSignupViewModel(); RequiredSkills = campaignEvent.RequiredSkills?.Select(acsk => acsk.Skill).ToList(); IsLimitVolunteers = campaignEvent.IsLimitVolunteers; IsAllowWaitList = campaignEvent.IsAllowWaitList; }
public async Task<object> RegisterEvent(EventSignupViewModel signupModel) { if (signupModel == null) { return HttpBadRequest(); } if (!ModelState.IsValid) { // this condition should never be hit because client side validation is being performed // but just to cover the bases, if this does happen send the erros to the client return Json(new { errors = ModelState.GetErrorMessages() }); } await _mediator.SendAsync(new EventSignupCommand { EventSignup = signupModel }); return new {Status = "success"}; }
public async Task<ActionResult> RegisterTask(EventSignupViewModel signupModel) { if (signupModel == null) return HttpBadRequest(); if (!ModelState.IsValid) { // this condition should never be hit because client side validation is being performed // but just to cover the bases, if this does happen send the erros to the client return Json(new { errors = ModelState.GetErrorMessages() }); } var result = await _mediator.SendAsync(new TaskSignupCommandAsync { TaskSignupModel = signupModel }); switch (result.Status) { case TaskSignupResult.SUCCESS: return Json(new { isSuccess = true, task = result.Task == null ? null : new TaskViewModel(result.Task, signupModel.UserId) }); case TaskSignupResult.FAILURE_CLOSEDTASK: return Json(new { isSuccess = false, errors = new string[] { FAILED_SIGNUP_TASK_CLOSED }, }); case TaskSignupResult.FAILURE_EVENTNOTFOUND: return Json(new { isSuccess = false, errors = new string[] { FAILED_SIGNUP_EVENT_NOT_FOUND }, }); case TaskSignupResult.FAILURE_TASKNOTFOUND: return Json(new { isSuccess = false, errors = new string[] { FAILED_SIGNUP_TASK_NOT_FOUND }, }); default: return Json(new { isSuccess = false, errors = new string[] { FAILED_SIGNUP_UNKOWN_ERROR }, }); } }
public async Task Register_ReturnsCorrectJson_WhenTaskIsClosed() { const string taskSignUpResultStatus = TaskSignupResult.FAILURE_CLOSEDTASK; var model = new EventSignupViewModel(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model))) .Returns(Task.FromResult(new TaskSignupResult { Status = taskSignUpResultStatus })); var sut = new TaskApiController(mediator.Object, null); var jsonResult = await sut.RegisterTask(model) as JsonResult; var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess"); var errors = jsonResult.GetValueForProperty<string[]>("errors"); Assert.False(successStatus); Assert.NotNull(errors); Assert.Equal(1, errors.Count()); Assert.Equal(TaskApiController.FAILED_SIGNUP_TASK_CLOSED, errors[0]); }
public async Task Register_ReturnsCorrectJson_WhenApiResult_IsSuccess() { const string taskSignUpResultStatus = TaskSignupResult.SUCCESS; var model = new EventSignupViewModel(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model))) .Returns(Task.FromResult(new TaskSignupResult { Status = taskSignUpResultStatus, Task = new AllReadyTask { Id = 1, Name = "Task" } })); var sut = new TaskApiController(mediator.Object, null); var jsonResult = await sut.RegisterTask(model) as JsonResult; var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess"); var taskModel = jsonResult.GetValueForProperty<TaskViewModel>("task"); Assert.True(successStatus); Assert.NotNull(taskModel); }
public async Task RegisterTaskSendsTaskSignupCommandWithCorrectTaskSignupModel() { var model = new EventSignupViewModel(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(y => y.TaskSignupModel == model))).Returns(Task.FromResult(new TaskSignupResult())); var sut = new TaskApiController(mediator.Object, null); await sut.RegisterTask(model); mediator.Verify(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(command => command.TaskSignupModel.Equals(model)))); }