public static int AddUserRole(UserRole role) { try { UsersDBEntities db = new UsersDBEntities(); db.UserRoles.Add(role); return db.SaveChanges(); } catch (Exception ex) { return -2; } }
public static int AddUser(User user) { try { UsersDBEntities db = new UsersDBEntities(); db.Users.Add(user); return db.SaveChanges(); } catch (Exception ex) { return -2; } }
public static int AssignRoleToUser(int UserID, int RoleID) { try { UsersDBEntities db = new UsersDBEntities(); UsersRolesMapping mapTableObj = new UsersRolesMapping() { UserID = UserID, UserRoleID = RoleID, }; db.UsersRolesMappings.Add(mapTableObj); return db.SaveChanges(); } catch (Exception ex) { return -2; } }
public static int DeleteRole(int id) { try { using (UsersDBEntities db = new UsersDBEntities()) { UserRole r = db.UserRoles.Single(role => role.UserRoleID == id); if (r != null) { db.UserRoles.Remove(r); return db.SaveChanges(); } else return 0; } } catch (Exception ex) { return -2; } }
public static int RemoveRoleFromUser(int UserID, int RoleID) { try { UsersDBEntities db = new UsersDBEntities(); if (db.UsersRolesMappings.Any(m => m.UserID == UserID & m.UserRoleID == RoleID)) { UsersRolesMapping mapObj = db.UsersRolesMappings.Single(m => m.UserID == UserID & m.UserRoleID == RoleID); db.UsersRolesMappings.Remove(mapObj); return db.SaveChanges(); } else return 0; } catch (Exception ex) { return -2; } }
public static int UpdateUser(User UpdatedUser) { UsersDBEntities db = new UsersDBEntities(); User u = (User)(from user in db.Users where user.UserID == UpdatedUser.UserID select user); if (u != null) { u.FirstName = UpdatedUser.FirstName; u.LastName = UpdatedUser.LastName; u.Password = UpdatedUser.Password; u.UserName = UpdatedUser.UserName; u.EmailAddress = UpdatedUser.EmailAddress; return db.SaveChanges(); } else return 0; }
public static int UpdateRole(UserRole UpdatedRole) { UsersDBEntities db = new UsersDBEntities(); UserRole r = (UserRole)(from user in db.Users where user.UserID == UpdatedRole.UserRoleID select user); if (r != null) { r.UserRoleName = UpdatedRole.UserRoleName; r.UserRoleDescription = UpdatedRole.UserRoleDescription; return db.SaveChanges(); } else return 0; }
public static int DeleteUser(int id) { try { using (UsersDBEntities db = new UsersDBEntities()) { User u = db.Users.Single(user => user.UserID == id); if (u != null) { db.Users.Remove(u); return db.SaveChanges(); } else return 0; } } catch (Exception ex) { return -2; } }
public static int UpdateUser(User UpdatedUser) { using (UsersDBEntities db = new UsersDBEntities()) { User u = db.Users.Single(user => user.UserID == UpdatedUser.UserID); if (u != null) { u.FirstName = UpdatedUser.FirstName; u.LastName = UpdatedUser.LastName; u.Password = UpdatedUser.Password; u.UserName = UpdatedUser.UserName; u.EmailAddress = UpdatedUser.EmailAddress; return db.SaveChanges(); } else return 0; } }
public static int UpdateRole(UserRole UpdatedRole) { using (UsersDBEntities db = new UsersDBEntities()) { UserRole r = db.UserRoles.Single(role => role.UserRoleID == UpdatedRole.UserRoleID); if (r != null) { r.UserRoleName = UpdatedRole.UserRoleName; r.UserRoleDescription = UpdatedRole.UserRoleDescription; return db.SaveChanges(); } else return 0; } }