Ejemplo n.º 1
0
        public async Task ModifyProject(string username, int projectId, KanbanProjectNewDTO newData)
        {
            if (string.IsNullOrWhiteSpace(newData.Name))
            {
                throw new Exception("Project name cannot be empty");
            }

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

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

            if (project == null)
            {
                throw new Exception("No project with ID [" + projectId.ToString() + "] for the user.");
            }

            if (newData.Name != project.Name)
            {
                if (await _context.KanbanProjects.FirstOrDefaultAsync(x => x.Name == newData.Name && x.ParentUser == user) != null)
                {
                    throw new Exception("Project name must be unique");
                }
            }

            project.Name  = newData.Name;
            project.Notes = newData.Notes;
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ModifyProject(int projectId, KanbanProjectNewDTO newProjectData)
        {
            var clientUsername = User.FindFirst(ClaimTypes.Name).Value;

            try
            {
                await _kanbanRepo.ModifyProject(clientUsername, projectId, newProjectData);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddProject(KanbanProjectNewDTO projectToAdd)
        {
            var clientUsername = User.FindFirst(ClaimTypes.Name).Value;

            var newProject = new KanbanProject();

            newProject.Name  = projectToAdd.Name;
            newProject.Notes = projectToAdd.Notes;

            try
            {
                await _kanbanRepo.AddProject(clientUsername, newProject);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok());
        }