public static TeamDelete GetModelView(Team team) { if (team == null) return null; var teamDelete = new TeamDelete(team); return teamDelete; }
public TeamDetails(Team team, int userId, bool isAdmin) { TeamId = team.TeamId; Title = team.Title; OwnerFullName = team.Owner.FullName; Note = String.IsNullOrEmpty(team.Note) ? NullDisplayText : team.Note; Task = String.IsNullOrEmpty(team.Task) ? NullDisplayText : team.Task; AllowEdit = team.OwnerId == userId || isAdmin; }
public static void Insert(DefaultContext db, int userId, Team team, int[] memberIds) { db.Teams.Add(team); IEnumerable<TeamMember> teamMembers = memberIds == null ? new TeamMember[0] : memberIds.Select(mi => new TeamMember { TeamId = team.TeamId, MemberId = mi }); foreach (var teamMember in teamMembers) { db.TeamMembers.Add(teamMember); } db.SaveChanges(); }
public static DeleteResult Delete(DefaultContext db, int id, out Team team) { team = GetDetail(db, id); if (team == null) return DeleteResult.AuthorizationFailed; try { var parameter = new SqlParameter(TeamIdSqlParameter, team.TeamId); db.Database.ExecuteSqlCommand(CascadeRemoveTeamProcedureTemplate, parameter); return DeleteResult.Ok; } catch (Exception e) { Logger.SetLog(e); return DeleteResult.DbFailed; } }
public static bool Update(DefaultContext db, int[] memberIds, ref Team team) { int teamId = team.TeamId; Team dbTeam = GetDetail(db, teamId); if (dbTeam == null) return false; dbTeam.CopyFrom(team); int[] dbMemberIds = dbTeam.TeamMembers.Select(tm => tm.MemberId).ToArray(); int[] deletedMemberIds = dbMemberIds.Except(memberIds).ToArray(); int[] newMemberIds = memberIds.Except(dbMemberIds).ToArray(); TeamMember[] deletedTeamMembers = deletedMemberIds.Select(dmi => db.TeamMembers.Where(tm => tm.TeamId == teamId && tm.MemberId == dmi)) .SelectMany(tm => tm).ToArray(); foreach (TeamMember teamMember in deletedTeamMembers) { db.TeamMembers.Remove(teamMember); } List<TeamMember> newTeamMembers = newMemberIds.Select(nmi => new TeamMember { TeamId = teamId, MemberId = nmi }).ToList(); foreach (TeamMember teamMember in newTeamMembers) { db.TeamMembers.Add(teamMember); } db.SaveChanges(); team = dbTeam; return true; }
private TeamIndex(Team team, int userId, bool isAdmin) { TeamId = team.TeamId; Title = team.Title; AllowEdit = team.OwnerId == userId || isAdmin; }
public Team GetModel(int userId) { var team = new Team { TeamId = TeamId, Title = Title, OwnerId = userId, Note = Note }; return team; }
public TeamEditNote(Team team) { TeamId = team.TeamId; Title = team.Title; Owner = team.Owner.FullName; Task = String.IsNullOrEmpty(team.Task) ? NullDisplayText : team.Task; Note = team.Note; }
private bool IsAccessForEdit(Team team) { if (team == null) return false; bool isAccess = IsAdmin || team.OwnerId == UserId; return isAccess; }
public TeamDelete(Team team) { Title = team.Title; }
public TeamEdit(Team team) { TeamId = team.TeamId; Title = team.Title; MemberIds = team.TeamMembers.Select(tm => tm.MemberId).ToArray(); Note = team.Note; Task = team.Task; }
public static TeamDetails GetModelView(Team team, int userId, bool isAdmin) { if (team == null) return null; var teamDetails = new TeamDetails(team, userId, isAdmin); return teamDetails; }
public void CopyNoteFrom(Team team) { Note = team.Note; }
public void CopyFrom(Team team) { Title = team.Title; Note = team.Note; Task = team.Task; }
private bool IsAccessForDelete(Team team) { bool isAccess = IsAccessForEdit(team); return isAccess; }
public static TeamEdit GetModelView(Team team) { if (team == null) return null; var teamEdit = new TeamEdit(team); return teamEdit; }
private bool IsAccessForDetails(Team team) { bool isAccess = IsAccessForEditNote(team); return isAccess; }
public Team GetModel(int userId, out int[] memberIds) { memberIds = MemberIds ?? new int[0]; var team = new Team { TeamId = TeamId, Title = Title, OwnerId = userId, Task = Task, Note = Note }; return team; }
private bool IsAccessForEditNote(Team team) { if (team == null) return false; bool isAccess = IsAdmin || team.OwnerId == UserId || team.TeamMembers.Any(tm => tm.MemberId == UserId); return isAccess; }
public static bool UpdateNote(DefaultContext db, ref Team team) { Team dbTeam = GetDetail(db, team.TeamId); if (dbTeam == null) return false; dbTeam.CopyNoteFrom(team); db.SaveChanges(); team = dbTeam; return true; }