Example #1
0
 public Team FindTeam(int teamId)
 {
     using (var access = new AccessDB())
     {
         Team team = access.ListOfTeams.FirstOrDefault(x => x.TeamName == teamId);
         return(team);
     }
 }
Example #2
0
 //On server's request database should return user if it exists...
 public User FindUser(string username)
 {
     using (var access = new AccessDB())
     {
         User user = access.ListOfUsers.FirstOrDefault(x => x.Username == username);
         return(user);
     }
 }
Example #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();
     }
 }
Example #4
0
        //public bool ChangePassword(User user, string newPassword)
        //{
        //    using (var access = new AccessDB())
        //    {
        //        foreach(User u in access.ListOfUsers)
        //        {
        //            if(u.Username == user.Username)
        //            {
        //                u.Password = newPassword;
        //                break;
        //            }

        //        }
        //        int i = access.SaveChanges();
        //        if (i > 0)
        //         {
        //                return true;
        //         }
        //    }
        //    return false;
        //}

        public bool AlreadyExists(string username)
        {
            using (var access = new AccessDB()) {
                var q = from b in access.ListOfUsers
                        where b.Username == username
                        select b;

                if (q.Any())
                {
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
        public List <User> UsersForJoin()
        {
            List <User> list = new List <User>();

            using (var access = new AccessDB())
            {
                foreach (User u in access.ListOfUsers)
                {
                    if (u.AskedToJoin == true)
                    {
                        list.Add(u);
                    }
                }
            }
            return(list);
        }
Example #6
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);
         }
     }
 }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
                }
            }
        }