public async Task <ActionResult> PostProjectMember(ProjectMemberList projectMembers) { var addedMembers = await DetermineMembers(projectMembers); if (addedMembers == null) { return(BadRequest()); } /* * // This code should be shared with the MM Controller * var addedMemberIds = (from am in addedMembers select am.UserId).ToList(); * var project = await _context.Projects.FindAsync(addedMembers[0].ProjectId); * * if (project.ManagerId != 0) * { * var managedMemberIds = from u in _context.Users * join mm in _context.ManagedMembers * on u.Id equals mm.UserId * where mm.ManagerId == project.ManagerId * select u.Id; * var unmanagedMemberIds = addedMemberIds.Except(managedMemberIds).Distinct().ToList(); * } */ _context.ProjectMembers.AddRange(addedMembers); await _context.SaveChangesAsync(); return(StatusCode(201)); }
private async Task <IActionResult> ChangeProjectManager(Project project, uint managerId) { if (managerId != 0) { User manager = await _context.Users.FindAsync(managerId); if (manager == null || manager.AccountType < 1) { return(BadRequest()); } // Gets all current project members var projectMembers = await(from pm in _context.ProjectMembers where pm.ProjectId == project.Id select pm.UserId).ToListAsync(); // If the individual made manager of the project is a member, add them if (!projectMembers.Contains(manager.Id)) { ProjectMember newMember = new ProjectMember() { ProjectId = project.Id, UserId = managerId }; _context.ProjectMembers.Add(newMember); } // Get all the project members that are not currently 'managed' by the new manager // Ignores any members that are admins or managers var unmanagedUsers = await(from ur in _context.UserRelationships join u in _context.Users on ur.UserAId equals u.Id where projectMembers.Contains(ur.UserAId) && ur.UserBId != manager.Id && ur.UserBSuperior && u.AccountType < manager.AccountType select ur.UserAId).ToListAsync(); // If there are any, add records indicating that they are managed by the new manager if (unmanagedUsers != null && unmanagedUsers.Count > 0) { var newMembers = new List <UserRelationship>(); unmanagedUsers.ForEach(user => newMembers.Add( new UserRelationship() { UserAId = user, UserBId = manager.Id, UserBSuperior = true } )); _context.UserRelationships.AddRange(newMembers); } } project.ManagerId = managerId; await _context.SaveChangesAsync(); return(NoContent()); }
private async Task <IActionResult> EditUserDetails(User user, UserDTO updatedUser) { user.FirstName = updatedUser.FirstName; user.LastName = updatedUser.LastName; user.Email = updatedUser.Email; try { await _context.SaveChangesAsync(); } catch (Exception) { throw; } return(NoContent()); }
private async Task <IActionResult> EditTicketFields(Ticket originalTicket, Ticket updatedTicket, uint editorId) { originalTicket.Name = updatedTicket.Name; originalTicket.Description = updatedTicket.Description; originalTicket.AssignedTo = updatedTicket.AssignedTo; originalTicket.Priority = updatedTicket.Priority; originalTicket.Status = updatedTicket.Status; originalTicket.Type = updatedTicket.Type; originalTicket.LastModifiedOn = DateTime.UtcNow; originalTicket.Status = updatedTicket.Status; var ticketHistory = Functions.TicketToHistory(originalTicket, editorId, "edit"); _context.TicketHistory.Add(ticketHistory); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> PutTicketHistory(uint ticketHistoryId, TicketHistory ticketHistory) { if (ticketHistoryId != ticketHistory.Id) { return(BadRequest()); } if (!TicketHistoryExists(ticketHistoryId)) { return(NotFound()); } _context.Entry(ticketHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception) { throw; } return(NoContent()); }
public async Task <IActionResult> PutManagedMember(uint?userAId, uint?userBId, UserRelationship managedMember) { if (!userAId.HasValue || !userBId.HasValue) { return(BadRequest()); } if (!ManagedMemberExists(userAId.Value, userBId.Value)) { return(NotFound()); } _context.Entry(managedMember).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception) { throw; } return(NoContent()); }
public async Task <IActionResult> PutComment(uint id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }