public bool IsLimitedUser(string userId) { using (OwinAuthDbContext db = new OwinAuthDbContext()) { int shipQuantit = db.BookByUser.Count(a => a.Users_Id == userId && a.ShipDate == null); return(shipQuantit > 3 ? true : false); } }
private void CreateRolesandUsers() { OwinAuthDbContext context = new OwinAuthDbContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); // In Startup iam creating first Admin Role and creating a default Admin User if (!roleManager.RoleExists("Admin")) { // first we create Admin rool var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); //Here we create a Admin super user who will maintain the website var user = new ApplicationUser(); user.UserName = "******"; user.Email = "*****@*****.**"; string userPWD = "P@ssw0rd123"; var chkUser = UserManager.Create(user, userPWD); //Add default User to Role Admin if (chkUser.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Admin"); } } // creating Creating Manager role if (!roleManager.RoleExists("Manager")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Manager"; roleManager.Create(role); } // creating Creating Employee role if (!roleManager.RoleExists("Employee")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Employee"; roleManager.Create(role); } }
public void ReserveAndReturn(int bookId, bool isReserve) { using (OwinAuthDbContext db = new OwinAuthDbContext()) { Book book = db.Book.Find(bookId); if (isReserve) { book.Quantity -= 1; } else { book.Quantity += 1; } db.Book.Attach(book); db.Entry(book).State = EntityState.Modified; db.SaveChanges(); } }