Пример #1
0
            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();
                    }
                }
            }
Пример #2
0
            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();
                    }
                }
            }