Example #1
0
        public async Task<IActionResult> Signup(EventSignupViewModel signupModel)
        {
            if (signupModel == null)
            {
                return HttpBadRequest();
            }

            if (ModelState.IsValid)
            {
                await _mediator.SendAsync(new EventSignupCommand { EventSignup = signupModel });
            }

            //TODO: handle invalid event 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(ShowEvent), new { id = signupModel.EventId });
        }
Example #2
0
        public EventViewModel(Models.Event @event)
        {
            Id = @event.Id;
            if (@event.Campaign != null)
            {
                CampaignId = @event.Campaign.Id;
                CampaignName = @event.Campaign.Name;
                TimeZoneId = @event.Campaign.TimeZoneId;
                if (@event.Campaign.ManagingOrganization != null)
                {
                    OrganizationId = @event.Campaign.ManagingOrganization.Id;
                    OrganizationName = @event.Campaign.ManagingOrganization.Name;
                    HasPrivacyPolicy = !string.IsNullOrEmpty(@event.Campaign.ManagingOrganization.PrivacyPolicy);
                }
            }

            Title = @event.Name;
            Description = @event.Description;
            EventType = @event.EventType;
            StartDateTime = @event.StartDateTime;
            EndDateTime = @event.EndDateTime;

            if (@event.Location != null)
            {
                Location = new LocationViewModel(@event.Location);
            }

            IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow;

            ImageUrl = @event.ImageUrl;

            Tasks = @event.Tasks != null
                 ? new List<TaskViewModel>(@event.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime))
                 : new List<TaskViewModel>();

            SignupModel = new EventSignupViewModel();

            //mgmccarthy: this check doesn't make much sense unless you explicitly set @event.RequiredSkills to null. If you look at the Event model, you'll see that RequireSkills is instaniated with
            //a new empty list: "public List<EventSkill> RequiredSkills { get; set; } = new List<EventSkill>();". I think this can go away?
            RequiredSkills = @event.RequiredSkills?.Select(ek => new SkillViewModel(ek.Skill)).ToList();

            IsLimitVolunteers = @event.IsLimitVolunteers;
            IsAllowWaitList = @event.IsAllowWaitList;
            Headline = @event.Headline;
        }
        public EventViewModel(Models.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 => new SkillViewModel(acsk.Skill)).ToList();
            IsLimitVolunteers = campaignEvent.IsLimitVolunteers;
            IsAllowWaitList = campaignEvent.IsAllowWaitList;
            Headline = campaignEvent.Headline;
        }
Example #4
0
        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 SignupSendsAsyncEventSignupCommandWithCorrrectDataWhenViewModelIsNotNull()
        {
            var builder = EventControllerBuilder.Instance();
            var sut = builder.WithMediator().Build();

            var model = new EventSignupViewModel();
            await sut.Signup(model);

            builder
                .MediatorMock
                .Verify(x => x.SendAsync(It.Is<EventSignupCommand>(y => y.EventSignup == model)));
        }
        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, 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("Signup failed - Task is 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, 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, null);
            await sut.RegisterTask(model);

            mediator.Verify(x => x.SendAsync(It.Is<TaskSignupCommandAsync>(command => command.TaskSignupModel.Equals(model))));
        }
Example #9
0
        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"};
        }