コード例 #1
0
        public IActionResult AddExistingUserToPlan(AddUserToPlanDTO addUserToPlan, int planId)
        {
            _loggerManager.Info($"AddExistingUserToPlan is requested");
            Response.StatusCode = StatusCodes.Status202Accepted;

            if (planId <= 0)
            {
                _loggerManager.Warn($"AddExistingUserToPlan requesy is bad");
                Response.StatusCode = StatusCodes.Status400BadRequest;

                return(PartialView("~/Views/User/Partials/_AddNewUser.cshtml"));
            }

            var existingUser = addUserToPlan.ExistingUser;

            if (TryValidateModel(existingUser))
            {
                var result = _planRepository.AddUserToPlan(existingUser.Id.Value, planId, existingUser.PositionId.Value);

                if (result)
                {
                    _loggerManager.Warn($"AddExistingUserToPlan successfully added an user");

                    Response.StatusCode = StatusCodes.Status201Created;
                }
                else
                {
                    _loggerManager.Warn($"AddExistingUserToPlan was unable to add user to a plan");

                    ModelState.AddModelError(string.Empty, sharedResource.userAddExistingUserToPlanProblem);
                }
            }
            else
            {
                _loggerManager.Warn($"AddExistingUserToPlan is invalid");
            }

            return(PartialView("~/Views/User/Partials/_AddExistingUser.cshtml"));
        }