public async Task<IActionResult> Signup(ActivitySignupViewModel signupModel) { if (signupModel == null) { return HttpBadRequest(); } if (ModelState.IsValid) { await _mediator.SendAsync(new ActivitySignupCommand { ActivitySignup = signupModel }); } //TODO: handle invalid activity signup info (phone, email) in a useful way // would be best to handle it in KO on the client side (prevent clicking Volunteer) return RedirectToAction(nameof(ShowActivity), new { id = signupModel.ActivityId }); }
public ActivityViewModel(Activity activity) { Id = activity.Id; if (activity.Campaign != null) { CampaignId = activity.Campaign.Id; CampaignName = activity.Campaign.Name; TimeZoneId = activity.Campaign.TimeZoneId; if (activity.Campaign.ManagingOrganization != null) { OrganizationId = activity.Campaign.ManagingOrganization.Id; OrganizationName = activity.Campaign.ManagingOrganization.Name; HasPrivacyPolicy = !string.IsNullOrEmpty(activity.Campaign.ManagingOrganization.PrivacyPolicy); } } Title = activity.Name; Description = activity.Description; ActivityType = activity.ActivityType; StartDateTime = activity.StartDateTime; EndDateTime = activity.EndDateTime; if (activity.Location != null) { Location = new LocationViewModel(activity.Location); } IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow; ImageUrl = activity.ImageUrl; //TODO Location Tasks = activity.Tasks != null ? new List<TaskViewModel>(activity.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime)) : new List<TaskViewModel>(); SignupModel = new ActivitySignupViewModel(); RequiredSkills = activity.RequiredSkills?.Select(acsk => acsk.Skill).ToList(); IsLimitVolunteers = activity.IsLimitVolunteers; IsAllowWaitList = activity.IsAllowWaitList; }
public ActivityViewModel(Activity activity) { Id = activity.Id; if (activity.Campaign != null) { CampaignId = activity.Campaign.Id; CampaignName = activity.Campaign.Name; TimeZoneId = activity.Campaign.TimeZoneId; if (activity.Campaign.ManagingOrganization != null) { OrganizationId = activity.Campaign.ManagingOrganization.Id; OrganizationName = activity.Campaign.ManagingOrganization.Name; HasPrivacyPolicy = !string.IsNullOrEmpty(activity.Campaign.ManagingOrganization.PrivacyPolicy); } } Title = activity.Name; Description = activity.Description; ActivityType = activity.ActivityType; StartDateTime = activity.StartDateTime; EndDateTime = activity.EndDateTime; if (activity.Location != null) { Location = new LocationViewModel(activity.Location); } IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow; ImageUrl = activity.ImageUrl; //TODO Location Tasks = activity.Tasks != null ? new List <TaskViewModel>(activity.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime)) : new List <TaskViewModel>(); SignupModel = new ActivitySignupViewModel(); RequiredSkills = activity.RequiredSkills?.Select(acsk => acsk.Skill).ToList(); IsLimitVolunteers = activity.IsLimitVolunteers; IsAllowWaitList = activity.IsAllowWaitList; }
public async Task<object> RegisterTask(ActivitySignupViewModel 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 TaskSignupCommand() { TaskSignupModel = signupModel }); return new {Status = result.Status, Task = (result.Task == null) ? null : new TaskViewModel(result.Task, signupModel.UserId)}; }
public async Task RegisterActivitySendsActivitySignupCommandAsyncWithCorrectData() { var model = new ActivitySignupViewModel(); var mediator = new Mock<IMediator>(); var sut = new ActivityApiController(mediator.Object); await sut.RegisterActivity(model); mediator.Verify(x => x.SendAsync(It.Is<ActivitySignupCommand>(command => command.ActivitySignup.Equals(model)))); }
public async Task<object> RegisterActivity(ActivitySignupViewModel 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 ActivitySignupCommand { ActivitySignup = signupModel }); return new {Status = "success"}; }