コード例 #1
0
ファイル: AgendaClass.cs プロジェクト: MarwaAlhazmi/TheBox
 public static List <AgendaTaskClass> GetAgendaTasks(string username, int agendaID)
 {
     using (boxEntities box = new boxEntities())
     {
         // user id
         int userid = Profile.GetUserID(username);
         var result = new List <AgendaTaskClass>();
         // check the user role if not creator then get the assigned to tasks only
         if (AgendaPrivacyClass.CheckRole(username, MeetingRoles.Creator, agendaID))
         {
             result = (from o in box.TaskAssigns.Include("TaskUsers").Include("UserProfile")
                       where o.AgendaID == agendaID
                       select new AgendaTaskClass()
             {
                 Title = o.TaskTitle,
                 Desc = o.TaskDesc,
                 TaskID = o.TaskID,
                 DueDate = o.DueDate,
                 CreatedDate = o.DateCreated,
             }).ToList();
             foreach (var t in result)
             {
                 t.Usernames = box.TaskUsers.Where(a => a.TaskID == t.TaskID).Select(a => a.UserProfile.UserName).ToArray();
             }
         }
         else
         {
             result = (from o in box.TaskUsers
                       where o.TaskAssign.AgendaID == agendaID && o.UserID == userid
                       select new AgendaTaskClass()
             {
                 Title = o.TaskAssign.TaskTitle,
                 Desc = o.TaskAssign.TaskDesc,
                 TaskID = o.TaskAssign.TaskID,
                 DueDate = o.TaskAssign.DueDate,
                 CreatedDate = o.TaskAssign.DateCreated,
             }).ToList();
         }
         return(result);
     }
 }
コード例 #2
0
ファイル: AgendaClass.cs プロジェクト: MarwaAlhazmi/TheBox
            public static AgendaTaskClass UpdateAgendaTask(int taskID, string username, int agendaID, string title, string desc, DateTime dueDate, string[] usernames)
            {
                using (boxEntities box = new boxEntities())
                {
                    usernames = usernames.Distinct().ToArray();
                    // get meetin id
                    var m = (from o in box.Agenda
                             where o.AgendaID == agendaID
                             select o.MeetingID).FirstOrDefault();

                    if (AgendaPrivacyClass.CheckRole(username, MeetingRoles.Creator, agendaID))
                    {
                        // get the header
                        var task = (from o in box.TaskAssigns.Include("TaskUsers")
                                    where o.TaskID == taskID
                                    select o).FirstOrDefault();
                        task.TaskTitle = title;
                        task.TaskDesc  = desc;
                        task.DueDate   = dueDate;
                        task.Creator   = Profile.getUserID(username);
                        box.SaveChanges();

                        // get the users
                        int[] NewUsers = { };
                        if (usernames.Contains("All"))
                        {
                            // get all users in meeting ids
                            NewUsers = AgendaPrivacyClass.ListParticipantIDs(agendaID);
                        }
                        else
                        {
                            NewUsers = Profile.GetUserIDs(usernames);
                        }
                        // get old users
                        int[] OldUsers = task.TaskUsers.Select(a => a.UserProfile.UserID).ToArray();
                        int[] same     = NewUsers.Intersect(OldUsers).ToArray();
                        // insert new
                        foreach (var t in NewUsers)
                        {
                            if (!same.Contains(t))
                            {
                                TaskUser u = new TaskUser();
                                u.UserID       = t;
                                u.TaskID       = task.TaskID;
                                u.AssignedDate = DateTime.Now;
                                task.TaskUsers.Add(u);
                            }
                        }
                        // delete
                        foreach (var o in OldUsers)
                        {
                            if (!same.Contains(o))
                            {
                                var dtask = task.TaskUsers.Where(a => a.UserID == o).FirstOrDefault();
                                if (dtask != null)
                                {
                                    task.TaskUsers.Remove(dtask);
                                }
                            }
                        }
                        box.SaveChanges();
                        // return object
                        AgendaTaskClass tt = new AgendaTaskClass();
                        tt.Title       = task.TaskTitle;
                        tt.Desc        = task.TaskDesc;
                        tt.DueDate     = task.DueDate;
                        tt.TaskID      = task.TaskID;
                        tt.CreatedDate = task.DateCreated;
                        tt.Usernames   = task.TaskUsers.Select(a => a.UserProfile.UserName).ToArray();

                        return(tt);
                    }
                    else
                    {
                        throw new UnauthorizedAccessException();
                    }
                }
            }
コード例 #3
0
ファイル: AgendaClass.cs プロジェクト: MarwaAlhazmi/TheBox
            public static AgendaTaskClass SaveAgendaTask(string username, int agendaID, string title, string desc, DateTime dueDate, string[] usernames)
            {
                AgendaTaskClass rObject = new AgendaTaskClass();

                using (boxEntities box = new boxEntities())
                {
                    usernames = usernames.Distinct().ToArray();


                    if (AgendaClass.AgendaPrivacyClass.CheckRole(username, MeetingRoles.Creator, agendaID))
                    {
                        // create the header
                        TaskAssign task = new TaskAssign();
                        task.AgendaID    = agendaID;
                        task.TaskTitle   = title;
                        task.TaskDesc    = desc;
                        task.DueDate     = dueDate;
                        task.DateCreated = DateTime.Now;
                        task.Creator     = Profile.getUserID(username);
                        box.TaskAssigns.AddObject(task);
                        box.SaveChanges();

                        // check if all
                        int[]    users = { };
                        string[] na    = { };
                        if (usernames.Contains("All"))
                        {
                            // get all users in meeting ids
                            users = AgendaPrivacyClass.ListParticipantIDs(agendaID);
                            na    = AgendaPrivacyClass.ListParticipantUsername(agendaID);
                        }
                        else
                        {
                            users = Profile.GetUserIDs(usernames);
                            na    = usernames;
                        }
                        foreach (var t in users)
                        {
                            TaskUser u = new TaskUser();
                            u.UserID       = t;
                            u.TaskID       = task.TaskID;
                            u.AssignedDate = DateTime.Now;
                            task.TaskUsers.Add(u);
                        }
                        box.SaveChanges();
                        rObject.TaskID      = task.TaskID;
                        rObject.CreatedDate = task.DateCreated;
                        rObject.DueDate     = task.DueDate;
                        rObject.Desc        = task.TaskDesc;
                        rObject.Title       = task.TaskTitle;
                        rObject.AgendaID    = agendaID;
                        rObject.Usernames   = na;
                        rObject.Creator     = username;

                        return(rObject);
                    }
                    else
                    {
                        throw new UnauthorizedAccessException();
                    }
                }
            }