Example #1
0
        public static TeamDelete GetModelView(Team team)
        {
            if (team == null)
                return null;

            var teamDelete = new TeamDelete(team);
            return teamDelete;
        }
Example #2
0
 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;
 }
Example #3
0
        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();
        }
Example #4
0
        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;
            }
        }
Example #5
0
        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;
        }
Example #6
0
 private TeamIndex(Team team, int userId, bool isAdmin)
 {
     TeamId = team.TeamId;
     Title = team.Title;
     AllowEdit = team.OwnerId == userId || isAdmin;
 }
Example #7
0
 public Team GetModel(int userId)
 {
     var team = new Team
     {
         TeamId = TeamId,
         Title = Title,
         OwnerId = userId,
         Note = Note
     };
     return team;
 }
Example #8
0
 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;
 }
Example #9
0
        private bool IsAccessForEdit(Team team)
        {
            if (team == null)
                return false;

            bool isAccess = IsAdmin || team.OwnerId == UserId;
            return isAccess;
        }
Example #10
0
 public TeamDelete(Team team)
 {
     Title = team.Title;
 }
Example #11
0
 public TeamEdit(Team team)
 {
     TeamId = team.TeamId;
     Title = team.Title;
     MemberIds = team.TeamMembers.Select(tm => tm.MemberId).ToArray();
     Note = team.Note;
     Task = team.Task;
 }
Example #12
0
        public static TeamDetails GetModelView(Team team, int userId, bool isAdmin)
        {
            if (team == null)
                return null;

            var teamDetails = new TeamDetails(team, userId, isAdmin);
            return teamDetails;
        }
Example #13
0
 public void CopyNoteFrom(Team team)
 {
     Note = team.Note;
 }
Example #14
0
 public void CopyFrom(Team team)
 {
     Title = team.Title;
     Note = team.Note;
     Task = team.Task;
 }
Example #15
0
 private bool IsAccessForDelete(Team team)
 {
     bool isAccess = IsAccessForEdit(team);
     return isAccess;
 }
Example #16
0
        public static TeamEdit GetModelView(Team team)
        {
            if (team == null)
                return null;

            var teamEdit = new TeamEdit(team);
            return teamEdit;
        }
Example #17
0
 private bool IsAccessForDetails(Team team)
 {
     bool isAccess = IsAccessForEditNote(team);
     return isAccess;
 }
Example #18
0
        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;
        }
Example #19
0
        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;
        }
Example #20
0
        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;
        }