public async Task <IActionResult> AddSprint([FromBody] AddSprintForm form)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ControllerErrorCode.WrongInputData));
            }

            var email = User.Identity.Name;

            var sprint = await _db.AddSprintAsync(email, form);

            if (sprint == null)
            {
                return(BadRequest(_db.Sprints.GetError()));
            }

            return(Ok(sprint.GetDTO()));
        }
        public async static Task <Sprint> AddSprintAsync(this ProjectContext db, string userEmail, AddSprintForm form)
        {
            var user = await db.Users.FirstOrDefaultAsync(x => x.Email.Equals(userEmail, StringComparison.OrdinalIgnoreCase));

            if (user == null)
            {
                _code = ControllerErrorCode.UserNotFound;
                return(null);
            }

            var role = await db.Roles.Include(y => y.Project).FirstOrDefaultAsync(x => x.Project.Id == form.ProjectId && x.User == user);

            if (role == null || role.Type != ProjectUserRole.ProjectManager)
            {
                _code = ControllerErrorCode.PermissionsDenied;
                return(null);
            }

            var sprint = new Sprint
            {
                Name       = form.SprintName,
                Project    = role.Project,
                ExpireDate = form.ExprieDate
            };

            await db.Sprints.AddAsync(sprint);

            await db.SaveChangesAsync();

            return(sprint);
        }