public IHttpActionResult UpdateProjectStory(int projectId, int storyId, UserStory model)
        {
            if (projectId != model.ProjectId || storyId != model.StoryId)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                var dbStory = _repoFactory.ProjectStories.GetProjectStories(projectId)
                              ?.SingleOrDefault(s => s.StoryId == storyId);
                if (dbStory == null)
                {
                    return(BadRequest());
                }

                var transaction = _repoFactory.BeginTransaction();
                try
                {
                    _repoFactory.ProjectStories.UpdateProjectStory(model, transaction);

                    _repoFactory.Sprints.DeleteStorySprintMapping(model.StoryId, transaction);
                    if (!string.IsNullOrWhiteSpace(model.SprintIds))
                    {
                        var sprintIds = model.SprintIds.Split(',');
                        foreach (var s in sprintIds)
                        {
                            if (int.TryParse(s, out var sprintId))
                            {
                                _repoFactory.Sprints.AddStoryToSprint(sprintId, model.StoryId, transaction);
                            }
                        }
                    }

                    _repoFactory.CommitTransaction();

                    if (!string.IsNullOrWhiteSpace(model.AssignedToUserId) &&
                        !string.Equals(model.AssignedToUserId, UserId, System.StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(dbStory.AssignedToUserId, model.AssignedToUserId, System.StringComparison.OrdinalIgnoreCase))
                    {
                        var receipientName = _cacheService.GetUserName(model.AssignedToUserId);
                        if (!string.IsNullOrWhiteSpace(receipientName))
                        {
                            var receipient    = new MailUser(model.AssignedToUserId, receipientName);
                            var actor         = new MailUser(UserId, DisplayName);
                            var userStoryLink = UrlFactory.GetUserStoryPageUrl(projectId, model.StoryId);
                            _emailService.SendMail(receipient, Core.Enumerations.EmailType.UserStoryAssigned, actor, userStoryLink);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    _repoFactory.RollbackTransaction();
                    _logger.Error(ex, Request.RequestUri.ToString());
                    return(InternalServerError(ex));
                }
                return(Ok());
            }
            return(BadRequest(ModelState));
        }
        public IHttpActionResult CreateQuickProjectStory(int projectId, UserStory model)
        {
            if (projectId != model.ProjectId)
            {
                return(NotFound());
            }

            model.RequestDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                var transaction = _repoFactory.BeginTransaction();
                try
                {
                    var newStoryId = _repoFactory.ProjectStories.CreateProjectStory(model, transaction);
                    if (newStoryId.HasValue)
                    {
                        model.StoryId = newStoryId.Value;
                        if (!string.IsNullOrWhiteSpace(model.SprintIds))
                        {
                            var sprintIds = model.SprintIds.Split(',');
                            foreach (var s in sprintIds)
                            {
                                if (int.TryParse(s, out var sprintId))
                                {
                                    _repoFactory.Sprints.AddStoryToSprint(sprintId, model.StoryId, transaction);
                                }
                            }
                        }
                        _repoFactory.CommitTransaction();

                        if (!string.IsNullOrWhiteSpace(model.AssignedToUserId) &&
                            !string.Equals(model.AssignedToUserId, UserId, System.StringComparison.OrdinalIgnoreCase))
                        {
                            var receipientName = _cacheService.GetUserName(model.AssignedToUserId);
                            if (!string.IsNullOrWhiteSpace(receipientName))
                            {
                                var receipient    = new MailUser(model.AssignedToUserId, receipientName);
                                var actor         = new MailUser(UserId, DisplayName);
                                var userStoryLink = UrlFactory.GetUserStoryPageUrl(projectId, model.StoryId);
                                _emailService.SendMail(receipient, Core.Enumerations.EmailType.UserStoryAssigned, actor, userStoryLink);
                            }
                        }

                        return(Created($"/api/{projectId}/projectstories/{model.StoryId}", model));
                    }
                }
                catch (System.Exception ex)
                {
                    _repoFactory.RollbackTransaction();
                    _logger.Error(ex, Request.RequestUri.ToString());
                    return(InternalServerError(ex));
                }
            }
            return(BadRequest(ModelState));
        }