예제 #1
0
        // GET: Users
        public ActionResult Index()
        {
            WebEntities db   = new WebEntities();
            var         list = db.UserAccounts.ToList();

            return(View(list));
        }
예제 #2
0
 public void Dispose()
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
 }
예제 #3
0
        public static bool CheckUserHasPermision(int userId, string permissionName)
        {
            int                          minute = 60;
            WebEntities                  context;
            List <AspNetRoles>           list  = new List <AspNetRoles>();
            List <BackendUserPermission> list2 = new List <BackendUserPermission>();

            if (Cache.Get("Roles") == null)
            {
                using (context = new WebEntities())
                {
                    list = context.AspNetRoles.AsEnumerable <AspNetRoles>().ToList <AspNetRoles>();
                    Cache.Set("Roles", list, minute);
                }
            }
            if (Cache.Get("BackendUserPermission") == null)
            {
                using (context = new WebEntities())
                {
                    list2 = context.BackendUserPermission.Include(s => s.BackendMenuAction).AsEnumerable <BackendUserPermission>().ToList <BackendUserPermission>();
                    Cache.Set("BackendUserPermission", list2, minute);
                }
            }
            IList <string> userRoles = new List <string>();

            if (Cache.Get("CurrentRoles") == null)
            {
                userRoles = UserManager.GetRoles(userId);
                Cache.Set("CurrentRoles", userRoles, minute);
            }
            userRoles = Cache.Get("CurrentRoles") as List <string>;
            list      = Cache.Get("Roles") as List <AspNetRoles>;
            list2     = Cache.Get("BackendUserPermission") as List <BackendUserPermission>;
            IList <string> strArray2 = userRoles;

            for (int i = 0; i < strArray2.Count; i++)
            {
                Func <BackendUserPermission, bool> predicate = null;
                string roleName = strArray2[i];

                List <BackendMenuAction> list3 = (from e in list2 select e.BackendMenuAction).ToList <BackendMenuAction>();
                foreach (BackendMenuAction permission in list3)
                {
                    if (permission.Name == permissionName)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #4
0
        public ActionResult GoogleLoginCallback()
        {
            var claimsPrincipal = HttpContext.User.Identity as ClaimsIdentity;

            var loginInfo = GoogleLoginViewModel.GetLoginInfo(claimsPrincipal);

            if (loginInfo == null)
            {
                return(RedirectToAction("Index"));
            }


            WebEntities db   = new WebEntities(); //DbContext
            var         user = db.UserAccounts.FirstOrDefault(x => x.Email == loginInfo.emailaddress);

            if (user == null)
            {
                user = new UserAccount
                {
                    Email      = loginInfo.emailaddress,
                    GivenName  = loginInfo.givenname,
                    Identifier = loginInfo.nameidentifier,
                    Name       = loginInfo.name,
                    SurName    = loginInfo.surname,
                    IsActive   = true
                };
                db.UserAccounts.Add(user);
                db.SaveChanges();
            }

            var ident = new ClaimsIdentity(
                new[] {
                // adding following 2 claim just for supporting default antiforgery provider
                new Claim(ClaimTypes.NameIdentifier, user.Email),
                new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),

                new Claim(ClaimTypes.Name, user.Name),
                new Claim(ClaimTypes.Email, user.Email),
                // optionally you could add roles if any
                new Claim(ClaimTypes.Role, "User")
            },
                CookieAuthenticationDefaults.AuthenticationType);


            HttpContext.GetOwinContext().Authentication.SignIn(
                new AuthenticationProperties {
                IsPersistent = false
            }, ident);
            return(Redirect("~/"));
        }
예제 #5
0
 public IQueryable<TheLoaiSP> getProductGroups()
 {
     var _db = new WebEntities();
     IQueryable<TheLoaiSP> query = _db.TheLoaiSPs;
     return query;
 }
예제 #6
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new WebEntities())
     {
         try
         {
             int CartItemCount = CartItemUpdates.Count();
             List<SanPhamDuocChon> myCart = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 // Iterate through all rows within shopping cart list
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.SanPham.ID == CartItemUpdates[i].ProductId)
                     {
                         if (CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.IDSanPham);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.IDSanPham, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
예제 #7
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new WebEntities())
     {
         try
         {
             var myItem = (from c in _db.SanPhamDuocChons where c.IDGioHang == updateCartID && c.SanPham.ID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.SoLuong = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
예제 #8
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new WebEntities())
     {
         try
         {
             var myItem = (from c in _db.SanPhamDuocChons where c.IDGioHang == removeCartID && c.SanPham.ID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.SanPhamDuocChons.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
예제 #9
0
 public IQueryable<DanhMucSanPham> GetCategories()
 {
     var _db = new WebEntities();
     IQueryable<DanhMucSanPham> query = _db.DanhMucSanPhams;
     return query;
 }