//Edits administrator with the specified userID
        public String editAdministrator(AdministratorQuery editAdmin)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    //Get privilege name
                    String privilege = (from p in context.privileges
                                        where p.privilegesID == editAdmin.privilegeID
                                        select p.privilegestType).FirstOrDefault();

                    //Check if admin had the privilege before
                    var admin = (from s in context.claims
                                 where s.userID == editAdmin.userID && s.privilegesID == editAdmin.privilegeID
                                 select s).FirstOrDefault();

                    //Get current--soon to be old privilege--- information
                    var oldAdmin = (from s in context.claims
                                    where s.userID == editAdmin.userID && s.privilegesID == editAdmin.oldPrivilegeID && s.deleted != true
                                    select s).FirstOrDefault();

                    if (oldAdmin != null && privilege != null)
                    {
                        //If the user has had the privilege before, recover record by setting deleted attribute to false
                        if (admin != null && admin.claimsID != oldAdmin.claimsID)
                        {
                            admin.deleted = false;
                            oldAdmin.deleted = true;

                            //If the user is an Administrator or 'Evaluator Committee' they receive Evaluator privileges
                            if (privilege != "Finance")
                            {
                                EvaluatorManager evaluator = new EvaluatorManager();
                                evaluator.addEvaluator(admin.user.membership.email);
                            }
                        }

                        else
                        {
                            //If the user has never had the new privilege to be assigned, substitute.
                            oldAdmin.privilegesID = editAdmin.privilegeID;

                            if (privilege != "Finance")
                            {
                                EvaluatorManager evaluator = new EvaluatorManager();
                                evaluator.addEvaluator(oldAdmin.user.membership.email);
                            }
                        }

                        //Send confirmation email.
                        try {sendEmailEditAdminConfirmation(oldAdmin.user.membership.email, privilege);}
                        catch (Exception ex)
                        {
                            Console.Write("AdminManager.sendeditAdminEmail error " + ex);
                            return null;
                        }

                        context.SaveChanges();
                        return privilege == "Admin" ? "Administrator" : privilege == "CommitteEvaluator" ? "Committee Evaluator" : privilege;
                    }
                    return null;
                }
            }
            catch (Exception ex)
            {
                Console.Write("AdminManager.editAdministrator error " + ex);
                return null;
            }
        }
        //Adds a new administrator with the specified userID and privilege
        public AdministratorQuery addAdmin(AdministratorQuery s)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    //Get privilege name
                    s.privilege = (from p in context.privileges
                                   where p.privilegesID == s.privilegeID
                                   select p.privilegestType).FirstOrDefault();

                    //Check if user is Member. Note: In the administrator tab the user has already been checked for membership.
                    var userInfo = (from user in context.users
                                    where user.membership.email == s.email
                                    select user).FirstOrDefault();

                    if (userInfo != null && s.privilege != null)
                    {
                        //User exists
                        s.userID = userInfo.userID;
                        s.firstName = userInfo.firstName;
                        s.lastName = userInfo.lastName;
                        s.email = userInfo.membership.email;

                        //Check if newAdmin has already a privilege
                        var checkAdmin = (from admin in context.claims
                                          where admin.userID == s.userID && admin.privilege.privilegestType != "Evaluator" && admin.deleted != true
                                          select admin).FirstOrDefault();

                        if (checkAdmin != null)
                        {
                            return null;
                        }

                        else
                        {
                            //Check if user has had the privilege before
                            var adminPrivilege = (from admin in context.claims
                                                  where admin.userID == s.userID && admin.privilege.privilegestType == s.privilege
                                                  select admin).FirstOrDefault();

                            if (adminPrivilege != null)
                            {
                                adminPrivilege.deleted = false;
                                context.SaveChanges();
                            }

                            else
                            {
                                //Add admin
                                claim newAdmin = new claim();
                                newAdmin.privilegesID = s.privilegeID;
                                newAdmin.deleted = false;
                                newAdmin.userID = s.userID;
                                context.claims.Add(newAdmin);
                                context.SaveChanges();
                            }

                            try { sendEmailConfirmation(s.email, s.privilege); }
                            catch (Exception ex)
                            {
                                Console.Write("AdminManager.sendnewAdminEmail error " + ex);
                                return null;
                            }

                            if (s.privilege != "Finance")
                            {
                                EvaluatorManager evaluator = new EvaluatorManager();
                                evaluator.addEvaluator(s.email);
                            }
                        }

                        s.privilege = s.privilege == "Admin" ? "Administrator" : s.privilege == "CommitteEvaluator" ? "Committee Evaluator" : s.privilege;

                        return s;
                    }

                    return null;
                }
            }
            catch (Exception ex)
            {
                Console.Write("AdminManager.addAdmin error " + ex);
                return null;
            }
        }
        //Removes administrator privileges to the user with the specified userID
        public bool deleteAdministrator(AdministratorQuery delAdmin)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    //Find user
                    var admin = (from s in context.claims
                                 where s.userID == delAdmin.userID && s.privilegesID == delAdmin.privilegeID && s.deleted != true
                                 select s).FirstOrDefault();
                    if (admin != null)
                    {
                        admin.deleted = true;
                    }
                    context.SaveChanges();

                    //Remove evaluator privileges if the user was an administrator or committee evaluator.
                    if (delAdmin.privilegeID != 2)
                    {
                        EvaluatorQuery evaluator = new EvaluatorQuery();
                        evaluator.userID = delAdmin.userID;
                        evaluator.acceptanceStatus = "Rejected";
                        EvaluatorManager manager = new EvaluatorManager();
                        manager.updateAcceptanceStatus(evaluator);
                    }

                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.Write("AdminManager.deleteAdministrator error " + ex);
                return false;
            }
        }