Exemplo n.º 1
0
        //logowanie
        public static Boolean LogIn(List <string> param)
        {
            string login    = param[0];
            string password = param[1];

            using (var db = new BlaBla_dbContext())
            {
                var userToEdit = db.Users.Where(x => x.Login == login && x.Password == password).FirstOrDefault();
                if (userToEdit != null)
                {
                    userToEdit.Status = true;
                    try
                    {
                        db.Entry(userToEdit).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        //Console.WriteLine("FAIL1");
                        //FAIL
                        return(false);
                    }
                }
                else
                {
                    //Console.WriteLine("FAIL2");
                    //FAIL
                    return(false);
                }
            }
            //OK
            //Console.WriteLine("OK");
        }
Exemplo n.º 2
0
        //rejestracja
        public static Boolean Register(List <string> param)
        {
            using (var db = new BlaBla_dbContext())
            {
                var    newUser = new User();
                string login   = param[0];

                int loginUnique = db.Users.Where(x => x.Login == login).Count();
                if (loginUnique == 0)
                {
                    newUser.Login    = login;
                    newUser.Password = param[1];
                    newUser.Status   = false;

                    db.Users.Add(newUser);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        //FAIL
                        return(false);
                    }
                }
                else
                {
                    //FAIL
                    return(false);
                }
            }
            //OK
            return(true);
        }
Exemplo n.º 3
0
        //dodawanie znajomego
        public static Boolean AddFriend(List <string> param)
        {
            string login1 = param[0]; //login1
            string login2 = param[1]; //login2

            using (var db = new BlaBla_dbContext())
            {
                var acquaintance = new Friendship();
                //find users IDs
                var userID1 = db.Users.Where(x => x.Login == login1).Select(x => x.Id_User).FirstOrDefault();
                if (userID1 != 0)
                {
                    var userID2 = db.Users.Where(x => x.Login == login2).Select(x => x.Id_User).FirstOrDefault();
                    if (userID2 != 0)
                    {
                        var acq = db.Friendships.Where(x => x.Id_User1 == userID1 && x.Id_User2 == userID2).FirstOrDefault();
                        if (acq == null)
                        {
                            acquaintance.Id_User1 = userID1;
                            acquaintance.Id_User2 = userID2;
                            try
                            {
                                db.Friendships.Add(acquaintance);
                                db.SaveChanges();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                Console.WriteLine("FAIL1");
                                //FAIL
                                return(false);
                            }
                        }
                        else
                        {
                            Console.WriteLine("FAIL2");
                            //FAIL
                            return(false);
                        }
                    }
                    else
                    {
                        Console.WriteLine("FAIL3");
                        //FAIL
                        return(false);
                    }
                }
                else
                {
                    Console.WriteLine("FAIL4");
                    //FAIL
                    return(false);
                }
            }
            //OK
            return(true);
        }
Exemplo n.º 4
0
        //usuwanie znajomego
        public static Boolean RemoveFriend(List <string> param)
        {
            string login1 = param[0]; //login1
            string login2 = param[1]; //login2

            using (var db = new BlaBla_dbContext())
            {
                var        id_user1 = db.Users.Where(x => x.Login == login1).Select(x => x.Id_User).FirstOrDefault();
                var        id_user2 = db.Users.Where(x => x.Login == login2).Select(x => x.Id_User).FirstOrDefault();
                Friendship friendship;
                Friendship friendship2;
                int        tmp = 0;

                friendship = db.Friendships.Where(x => x.Id_User1 == id_user1 && x.Id_User2 == id_user2).FirstOrDefault();
                if (friendship != null)
                {
                    db.Friendships.Remove(friendship);
                    db.SaveChanges();
                    tmp++;
                }

                friendship2 = db.Friendships.Where(x => x.Id_User1 == id_user2 && x.Id_User2 == id_user1).FirstOrDefault();
                if (friendship2 != null)
                {
                    db.Friendships.Remove(friendship2);
                    db.SaveChanges();
                    tmp++;
                }

                if (tmp > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        //dodanie info o połączeniu
        public static Boolean addVoiceHistory(List <string> param)
        {
            string   caller   = param[0];
            string   receiver = param[1];
            TimeSpan duration = TimeSpan.Parse(param[2]);
            DateTime date     = DateTime.Now;

            using (var db = new BlaBla_dbContext())
            {
                VoiceHistory vh = new VoiceHistory();
                vh.Id_Caller   = db.Users.Where(x => x.Login == caller).Select(x => x.Id_User).FirstOrDefault();
                vh.Id_Receiver = db.Users.Where(x => x.Login == receiver).Select(x => x.Id_User).FirstOrDefault();
                vh.Duration    = duration;
                vh.CallDate    = date;
                db.VoiceHistories.Add(vh);
                db.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 6
0
        //zmiana hasła
        public static Boolean ChangePass(List <string> param)
        {
            string login   = param[0];
            string oldpass = param[1];
            string newpass = param[2];

            //sprawdzenie czy haslo stare poprawne
            using (var db = new BlaBla_dbContext())
            {
                var user = db.Users.Where(x => x.Login == login && x.Password == oldpass).FirstOrDefault();

                if (user != null)
                {
                    user.Password = newpass;
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }