Пример #1
0
        public async Task AddStory(string username, string projectName, KanbanStory newStory)
        {
            if (string.IsNullOrWhiteSpace(newStory.Name))
            {
                throw new Exception("Story name cannot be empty");
            }

            var user = await _context.Users.FirstOrDefaultAsync(x => x.Username == username);

            var project = await _context.KanbanProjects.FirstOrDefaultAsync(x => x.Name == projectName && x.ParentUser == user);

            if (project == null)
            {
                throw new Exception("Invalid project: [" + projectName + "]");
            }

            if (await _context.KanbanStories.FirstOrDefaultAsync(x => x.Name == newStory.Name && x.ParentProject == project) != null)
            {
                throw new Exception("Story name must be unique within project.");
            }

            newStory.ParentProject = project;

            await _context.KanbanStories.AddAsync(newStory);

            _context.SaveChanges();
        }
Пример #2
0
        public async Task <IActionResult> AddStory(KanbanStoryNewDTO storyToAdd)
        {
            var clientUsername = User.FindFirst(ClaimTypes.Name).Value;

            var newStory = new KanbanStory();

            newStory.Name  = storyToAdd.Name;
            newStory.Notes = storyToAdd.Notes;

            try
            {
                await _kanbanRepo.AddStory(clientUsername, storyToAdd.ProjectName, newStory);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok());
        }