Beispiel #1
0
        public bool NameBoss(string username, int teamId)   //PR
        {
            User user = FindUser(username);
            Team team = FindTeam(teamId);

            using (var access = new AccessDB())
            {
                if (team.BossId == -1 && user.Team != team.TeamName)
                {
                    user.Group = "Boss";

                    access.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    access.SaveChanges();


                    team.BossId = user.Id;
                    access.Entry(team).State = System.Data.Entity.EntityState.Modified;

                    access.SaveChanges();

                    foreach (User u in access.ListOfUsers)
                    {
                        if (u.Team == teamId)
                        {
                            u.BossId = team.BossId;
                        }
                    }
                    access.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        public bool AddRequest(string username, string start, string end)
        {
            User    user    = FindUser(username);
            Request request = new Request(start, end, user.Id);



            using (var access = new AccessDB())
            {
                do
                {
                    user = access.ListOfUsers.FirstOrDefault(x => x.Id == user.BossId);
                    request.RequestManagers += user.Id + " ";
                } while (user.BossId != -1);

                access.ListOfRequests.Add(request);
                int i = access.SaveChanges();

                if (i > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #3
0
 public void Ask(User user)
 {
     using (var access = new AccessDB())
     {
         user.AskedToJoin         = true;
         access.Entry(user).State = System.Data.Entity.EntityState.Modified;
         access.SaveChanges();
     }
 }
Beispiel #4
0
 public bool UpdateUser(User user)
 {
     using (var access = new AccessDB())
     {
         try
         {
             access.Entry(user).State = System.Data.Entity.EntityState.Modified;
             access.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             return(false);
         }
     }
 }
Beispiel #5
0
        public bool DenyRequest(int id, string username)
        {
            User    user = FindUser(username);
            Request req  = new Request();

            using (var access = new AccessDB())
            {
                foreach (Request r in access.ListOfRequests)
                {
                    if (r.Id == id)
                    {
                        DateTime dateOfRequest = r.TimeOfRequest;
                        DateTime now           = DateTime.Now;
                        TimeSpan interval      = now - dateOfRequest;
                        if (interval.Minutes > 100)        //.Days>7
                        {
                            return(false);
                        }
                        else
                        {
                            string[] bossString = r.RequestManagers.Split(' ');
                            foreach (string s in bossString)
                            {
                                if (Int32.Parse(s) == user.Id)
                                {
                                    r.Denied   = true;
                                    r.Approved = false;
                                    req        = r;
                                    WriteToXmlDeny(r, DateTime.Now);
                                    DeleteFromXml(r);
                                    break;
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
                access.Entry(req).State = System.Data.Entity.EntityState.Modified;
                access.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #6
0
        public bool AddUser(User user)
        {
            if (AlreadyExists(user.Username) == false)
            {
                using (var access = new AccessDB())
                {
                    access.ListOfUsers.Add(user);
                    int i = access.SaveChanges();
                    if (i > 0)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                throw new Exception("User already exists with that name!");
            }

            return(false);
        }
Beispiel #7
0
        public bool ApproveRequest(int id, string username)
        {
            using (var access = new AccessDB())
            {
                User user = access.ListOfUsers.FirstOrDefault(x => x.Username == username);

                Request request = access.ListOfRequests.FirstOrDefault(x => x.Id == id);

                char c      = request.RequestManagers[0]; //Prvi boss
                int  bossID = Int32.Parse(c.ToString());
                if (user.Id == bossID)
                {
                    request.Approved = true;
                    WriteToXmlApproved(request, DateTime.Now);
                    access.Entry(request).State = System.Data.Entity.EntityState.Modified;
                    access.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
        public bool AddToTeam(string username, int teamId) //PR
        {
            using (var access = new AccessDB())
            {
                User user = FindUser(username);
                user.Team        = teamId;
                user.AskedToJoin = false;

                Team t = FindTeam(teamId);

                if (t == null)
                {
                    t = new Team()
                    {
                        TeamName = teamId, BossId = -1
                    };
                    access.ListOfTeams.Add(t);
                }

                if (t.BossId != -1)
                {
                    user.BossId = t.BossId;
                }

                try
                {
                    access.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    access.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
            }
        }