Exemplo n.º 1
0
        public ActionResult editProfile()
        {
            string  firstname    = Request.Form["firstName"].ToString();
            string  lastname     = Request.Form["lastName"].ToString();
            string  bio          = Request.Form["biography"].ToString();
            string  pass         = Request.Form["password"].ToString();
            string  repass       = Request.Form["repassword"].ToString();
            Profile oldDBProfile = GetProfile();
            users   oldDBUser    = GetUser();

            oldDBUser.firstName    = firstname;
            oldDBUser.lastName     = lastname;
            oldDBProfile.biography = bio;
            if (pass != "" && pass == repass)
            {
                oldDBUser.password = pass;
            }
            else if (pass != "" && pass != repass)
            {
                TempData["ERROR"] = "Unmatched Passwords! , try again.";
            }

            usersDal   udal = new usersDal();
            profileDal pdal = new profileDal();

            udal.userLst.RemoveRange(udal.userLst.Where(x => x.username == oldDBUser.username));
            udal.SaveChanges();
            udal.userLst.Add(oldDBUser);
            udal.SaveChanges();
            pdal.profilesList.RemoveRange(pdal.profilesList.Where(x => x.username == oldDBProfile.username));
            pdal.SaveChanges();
            pdal.profilesList.Add(oldDBProfile);
            pdal.SaveChanges();
            return(RedirectToAction("MyProfile", "User"));
        }
        public ActionResult DeleteUser(string delete)
        {
            profileDal       pdal  = new profileDal();
            UsersStatusDal   usdal = new UsersStatusDal();
            notificationsDal ndal  = new notificationsDal();
            friendsDal       fdal  = new friendsDal();
            String           toDelete;

            try
            {
                toDelete = Request.Form["row"].ToString();
            }
            catch (Exception)
            {
                toDelete = delete;
            }

            udal.userLst.RemoveRange(udal.userLst.Where(x => x.username.Equals(toDelete)));
            adal.adminsLst.RemoveRange(adal.adminsLst.Where(x => x.username.Equals(toDelete)));
            pdal.profilesList.RemoveRange(pdal.profilesList.Where(x => x.username.Equals(toDelete)));
            usdal.statuses.RemoveRange(usdal.statuses.Where(x => x.username.Equals(toDelete)));
            ndal.nLst.RemoveRange(ndal.nLst.Where(x => x.username.Equals(toDelete) || x.uFrom.Equals(toDelete)));
            fdal.FriendsLst.RemoveRange(fdal.FriendsLst.Where(x => x.username.Equals(toDelete)));
            fdal.FriendsLst.RemoveRange(fdal.FriendsLst.Where(x => x.friendUsername.Equals(toDelete)));

            udal.SaveChanges();
            adal.SaveChanges();
            pdal.SaveChanges();
            usdal.SaveChanges();
            ndal.SaveChanges();
            fdal.SaveChanges();

            return(RedirectToAction("usersList", "Admin"));
        }
Exemplo n.º 3
0
        public void addNewAdmin()
        {
            users    usr;
            usersDal udal = new usersDal();

            List <admins> alist = (from x in adal.adminsLst where x.username.Equals("test") select x).ToList <admins>();

            if (alist.Count == 1)
            {
                adal.adminsLst.RemoveRange(adal.adminsLst.Where(x => x.username.Equals("test")));
                adal.SaveChanges();
            }
            List <users> list = (from x in udal.userLst where x.username.Equals("test") select x).ToList <users>();

            if (list.Count == 0)
            {
                usr = new users {
                    email = "*****@*****.**", firstName = "test", lastName = "test", username = "******", password = "******"
                };
                udal.userLst.Add(usr);
                udal.SaveChanges();
            }


            admins adm = new admins {
                username = "******", aLevel = "A"
            };

            controller.NewAdmin(adm);

            List <admins> listtest = (from x in adal.adminsLst where x.username.Equals("test") select x).ToList <admins>();

            Assert.AreEqual(listtest.Count, 1);
        }
Exemplo n.º 4
0
        public ActionResult Login()
        {
            usersDal adal = new usersDal();

            adal.SaveChanges();
            return(View());
        }
Exemplo n.º 5
0
        public void delete_test_user()
        {
            usersDal     udal       = new usersDal();
            List <users> check_user = (from x in udal.userLst where x.username.Equals("test") select x).ToList <users>();

            if (check_user.Count == 1)
            {
                udal.userLst.RemoveRange(udal.userLst.Where(x => x.username.Equals("test")));
                udal.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public ActionResult RegAction(users userReg)
        {
            usersDal       emails   = new usersDal();
            profileDal     pdal     = new profileDal();
            UsersStatusDal usdal    = new UsersStatusDal();
            List <users>   checkLSt = (from tmp in emails.userLst where tmp.email.Contains(userReg.email) select tmp).ToList <users>();

            if (checkLSt.Count > 0)
            {
                ViewData["eMess"] = "This e-mail has registered before\n try another one.";
            }
            else
            {
                if (userReg.password != Request.Form["rePass"])
                {
                    ViewData["pMess"] = "The passwords doesn't match";
                }
                else if (userReg.password.Length < 6)
                {
                    ViewData["pMess"] = "The password length must be greater than 6";
                }
                else
                {
                    Profile        profile    = new Profile();
                    usersStatus    uss        = new usersStatus();
                    List <Profile> defProfile = (from x in pdal.profilesList
                                                 where x.username.Equals("testImage")
                                                 select x).ToList <Profile>();
                    emails.userLst.Add(userReg);
                    emails.SaveChanges();
                    profile.username  = userReg.username;
                    profile.biography = "empty";
                    profile.image     = defProfile[0].image;
                    pdal.profilesList.Add(profile);
                    uss.username = userReg.username;
                    uss.status   = "Activated";
                    usdal.statuses.Add(uss);
                    usdal.SaveChanges();

                    try
                    {
                        pdal.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    return(View("Login"));
                }
            }
            return(View("Register"));
        }
        public void  new_user_Register()
        {
            users usr = new users {
                email = "*****@*****.**", firstName = "test", lastName = "test", username = "******", password = "******"
            };
            usersDal udal = new usersDal();

            udal.userLst.RemoveRange(udal.userLst.Where(x => x.username.Equals(usr.username)));
            udal.userLst.Add(usr);
            udal.SaveChanges();
            List <users> database = (from x in udal.userLst where x.username == usr.username select x).ToList <users>();

            Assert.AreEqual(database.Count, 1);
        }
Exemplo n.º 8
0
        public void get_users_information()
        {
            usersDal udal = new usersDal();
            users    usr;

            delete_test_user();
            List <users> list         = (from x in udal.userLst select x).ToList <users>();
            int          users_number = list.Count;


            //Add a new user.
            usr = new users {
                email = "*****@*****.**", firstName = "test", lastName = "test", username = "******", password = "******"
            };
            udal.userLst.Add(usr);
            udal.SaveChanges();

            list = (from x in udal.userLst select x).ToList <users>();

            //Check if gett all users correctly!
            Assert.AreEqual(users_number + 1, list.Count);
        }