Exemple #1
0
        private void UnBlockFromDB(string uName, int inst, int dep, int yeId)
        {
            List <Blocked> bd   = new List <Blocked>();
            BlockedDal     bdal = new BlockedDal();

            try
            {
                bd =
                    (from x in bdal.Blockeds
                     where x.UserName == uName
                     select x).ToList <Blocked>();
            }
            catch
            {
            }

            foreach (Blocked b in bd)
            {
                if (b.InsId == inst && b.DepId == dep && b.YearId == yeId && b.Bdate > DateTime.Today)
                {
                    b.InsId  = -1;
                    b.DepId  = -1;
                    b.YearId = -1;

                    bdal.SaveChanges();
                }
            }
        }
        private void BlockFromDB(string uName, DateTime date, int inst, int dep, int yeId)
        {
            Blocked blocked = new Blocked()
            {
                UserName = uName,
                InsId    = inst,
                DepId    = dep,
                YearId   = yeId,
                Bdate    = date
            };
            BlockedDal Bdal = new BlockedDal();

            Bdal.Blockeds.Add(blocked);
            Bdal.SaveChanges();
        }
Exemple #3
0
        public void TestBlockUser()
        {
            //Arrange
            var controller = new ManagerControllerTests();
            //Add Manager User
            UserDal usrDal      = new UserDal();
            User    managerUser = new User
            {
                UserName       = "******",
                Password       = "******",
                rank           = 1,
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                active         = true
            };

            usrDal.Users.Add(managerUser);
            usrDal.SaveChanges();

            managerUser = usrDal.Users.SingleOrDefault(b => b.UserName == "TestManagerUser");
            //Add to managing connection
            ManageConnectionDal magDal = new ManageConnectionDal();
            ManageConnection    magObj = new ManageConnection
            {
                managerId   = managerUser.id,
                institution = 1,
                sYear       = -1,
                department  = -1
            };

            magDal.ManageConnections.Add(magObj);
            magDal.SaveChanges();
            //Add User to be blocked
            User blockedUser = new User
            {
                UserName       = "******",
                Password       = "******",
                rank           = 0,
                Email          = "*****@*****.**",
                active         = true,
                EmailConfirmed = true
            };

            usrDal.Users.Add(blockedUser);
            usrDal.SaveChanges();

            //Act
            controller.BlockUser(managerUser, "NewUser", DateTime.Now, 1, -1, -1);

            //Assert
            BlockedDal blkdal = new BlockedDal();

            List <Blocked> blk =
                (from x in blkdal.Blockeds
                 where x.UserName == blockedUser.UserName
                 select x).ToList();

            Assert.AreEqual(blk[0].UserName.Replace(" ", ""), blockedUser.UserName.Replace(" ", ""));

            //Clean up
            usrDal.Users.Remove(managerUser);
            usrDal.Users.Remove(blockedUser);
            usrDal.SaveChanges();

            magDal.ManageConnections.Remove(magObj);
            magDal.SaveChanges();

            blkdal.Blockeds.Remove(blk[0]);
            blkdal.SaveChanges();
        }