public bool Invoke(int id) { var userToDelete = userRepository.GetById(id); if (userToDelete == null) { return(false); } userRepository.Delete(userToDelete); userRepository.Save(); var userApps = userAppRepository.GetAll(); var appsToDelete = (from app in userApps where app.User.Id == id select app).ToList(); if (appsToDelete == null || appsToDelete.Count == 0) { return(false); } foreach (var app in appsToDelete) { userAppRepository.Delete(app); } userAppRepository.Save(); return(true); }
public bool Invoke(int appId, int user, UserRole newRole) { var userFromDB = userRepository.GetById(user); if (userFromDB == null || userFromDB.IsSuperAdmin && newRole == UserRole.SuperAdmin) { return(false); } var userApp = userAppRepository.FindBy(m => m.User.Id == user && m.App.Id == appId).FirstOrDefault(); if (userApp == null && !userFromDB.IsSuperAdmin) { return(false); } if (userApp == null && userFromDB.IsSuperAdmin) { // Set IsSuperAdmin flag to false userFromDB.IsSuperAdmin = false; userRepository.Edit(userFromDB); userRepository.Save(); // Add new user to this app with newRole var newUserApp = new UserAppModel { AppId = appId, UserId = user, Role = newRole }; addNewUserApp.Invoke(newUserApp); return(true); } var userRole = (UserRole)userApp.Role; if (userRole.Equals(newRole) || newRole > userRole) { if (!userFromDB.IsSuperAdmin) { return(false); } // Set IsSuperAdmin flag to false userFromDB.IsSuperAdmin = false; userRepository.Edit(userFromDB); userRepository.Save(); return(true); } userApp.Role = (DataAccess.Enums.UserRole)newRole; userAppRepository.Edit(userApp); userAppRepository.Save(); return(true); }
public bool Invoke(int userId, int appId) { var appToDelete = userAppRepository.FindBy(x => x.User.Id == userId && x.App.Id == appId).FirstOrDefault(); if (appToDelete == null) { return(false); } userAppRepository.Delete(appToDelete); userAppRepository.Save(); return(true); }
public int Invoke(UserAppModel model) { var userApp = new DataAccess.Models.UserApps() { User = userRepository.GetById(model.UserId), App = appRepository.GetById(model.AppId), Role = (DataAccess.Enums.UserRole)Enum.Parse(typeof(DataAccess.Enums.UserRole), model.Role.ToString()), }; if (userApp.User == null || userApp.App == null || userAppRepository.FindBy(x => x.App.Id == userApp.App.Id && x.User.Id == userApp.User.Id).Any()) { return(0); } userAppRepository.Add(userApp); userAppRepository.Save(); return(userApp.Id); }
public bool Invoke(int appId, int user, UserRole newRole) { var userFromDb = userRepository.GetById(user); if (userFromDb == null || userFromDb.IsSuperAdmin) { return(false); } if (newRole == UserRole.SuperAdmin) { userFromDb.IsSuperAdmin = true; userRepository.Edit(userFromDb); userRepository.Save(); return(true); } var userApp = userAppRepository.FindBy(m => m.User.Id == user && m.App.Id == appId).FirstOrDefault(); if (userApp == null) { return(false); } var userRole = (UserRole)userApp.Role; if (userRole.HasRole(newRole)) { return(false); } userApp.Role = (DataAccess.Enums.UserRole)newRole; userAppRepository.Edit(userApp); userAppRepository.Save(); return(true); }