public override string[] GetRolesForUser(string username)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }
            var cachKey = string.Format("{0}_role", username);

            if (HttpRuntime.Cache[cachKey] != null)
            {
                return((string[])HttpRuntime.Cache[cachKey]);
            }
            string[] roles = new string[] { };
            using (InstituteDbContext db = new InstituteDbContext())
            {
                roles = (from r in db.SecurityRoles
                         join ur in db.UserSecurityRoles on r.RoleId equals ur.UserRoleId
                         where ur.UserName.Equals(username)
                         select r.RoleName).ToArray <string>();
                if (roles.Count() > 0)
                {
                    HttpRuntime.Cache.Insert(cachKey, roles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMunite), Cache.NoSlidingExpiration);
                }
            }
            return(roles);
        }
Esempio n. 2
0
        public void Create()
        {
            InstituteDbContext res = new InstituteDbContext();

            Batch batch = new Batch
            {
                BatchName = "39Batch" + DateTime.Now.ToString(),
                Branch    = new Branch
                {
                    BranchName = "TestBranch",

                    Institute = new Common.Models.Institute {
                        InstituteName = "Test Institute"
                    }
                }
            };

            res.Set <Batch>().Add(batch);
            res.SaveChanges();

            Batch batch1 = res.Set <Batch>().Where(B => B.BatchName == batch.BatchName).FirstOrDefault();

            string expected = batch.BatchName;
            string actual   = batch1.BatchName;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        public void Delete()
        {
            InstituteDbContext res = new InstituteDbContext();

            Batch batch = new Batch
            {
                BatchName = "39Batch" + DateTime.Now.ToString(),
                Branch    = new Branch
                {
                    BranchName = "TestBranch",

                    Institute = new Common.Models.Institute {
                        InstituteName = "Test Institute"
                    }
                }
            };

            res.Set <Batch>().Add(batch);
            res.SaveChanges();

            Batch batch1 = res.Set <Batch>().Where(B => B.BatchName == batch.BatchName).FirstOrDefault();

            res.Set <Batch>().Remove(batch);
            res.SaveChanges();



            Batch batch2 = res.Set <Batch>().Where(B => B.BatchName == batch.BatchName).FirstOrDefault();



            // Assert.AreNotEqual(null, batch2);
            Assert.AreEqual(null, batch2);
        }
Esempio n. 4
0
        public void GetAll()
        {
            InstituteDbContext res = new InstituteDbContext();

            List <Batch> list = res.Set <Batch>().ToList();

            foreach (Batch batch in list)
            {
                Console.WriteLine("Ashan Tharuka : " + batch.BatchId);
            }
        }
Esempio n. 5
0
        public void FindById()
        {
            InstituteDbContext res = new InstituteDbContext();


            Batch batch1 = res.Set <Batch>().Find(99);

            int expected = 99;
            int actual   = batch1.BatchId;

            Assert.AreEqual(expected, actual);
        }