コード例 #1
0
        public async Task <IActionResult> AttendToTravelPlan([FromQuery] AttendToTravelPlanInput input)
        {
            try
            {
                using (var scope = _provider.CreateScope())
                {
                    var userService = scope.ServiceProvider.GetService <UserService>();
                    var result      = userService.AttendToTravelPlan(input.UserId, input.TravelPlanId);
                    var dto         = new AttendToTravelPlanDto();
                    dto.Status = result;

                    if (result == AttendStatus.Successful)
                    {
                        dto.Message = "Successfully attended to travel plan.";
                        return(Ok(dto));
                    }
                    else
                    {
                        if (result == AttendStatus.NoSeatsAvailable)
                        {
                            dto.Message = "No seats available.";
                        }
                        else if (result == AttendStatus.IsOwner)
                        {
                            dto.Message = "Attender is the owner of the travel plan";
                        }
                        else if (result == AttendStatus.AlreadyAttended)
                        {
                            dto.Message = "Already attended.";
                        }
                        else if (result == AttendStatus.UserDoesntExist)
                        {
                            dto.Message = "User doesn't exist";
                        }
                        else
                        {
                            dto.Message = "Couldn't attend to travel plan.";
                        }
                        return(BadRequest(dto));
                    }
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { Message = e.Message }));
            }
        }
コード例 #2
0
        public async void AttendToTravelPlan_ReturnsBadRequest_WithoutAnyUsersAndTravelPlans()
        {
            // Arrange
            var input = new AttendToTravelPlanInput
            {
                TravelPlanId = 1,
                UserId       = 1,
            };

            string queryString = "TravelPlanId={0}&UserId={1}";

            queryString = String.Format(queryString, input.TravelPlanId, input.UserId);

            // Act
            var response = await TestClient.PostAsync("/User/AttendToTravelPlan?" + queryString, null); // body is null

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }