Example #1
0
        public async Task <IActionResult> CreateProject([FromBody] CreateProjectViewModel model)
        {
            if (model.FktUser == 0)
            {
                model.FktUser = Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier));
            }

            if (!HttpContext.User.IsInRole("admin") && !_getAccessUser.UserCookieIs(HttpContext, model.FktUser.ToString()))
            {
                return(StatusCode(403, "Access Denied !"));
            }

            Result <int> result = await _projectGateway.CreateProject(model.FktUser, model.Name, model.Description, 3, model.IsPublic);

            if (result.ErrorMessage == "Project with this name already exists")
            {
                return(BadRequest(result.ErrorMessage));
            }

            return(Ok("Project has been created"));
        }