private void CheckRolesAndSuperUser() { UsersHelpers.CheckRole("Admin"); UsersHelpers.CheckRole("User"); UsersHelpers.CheckSuperUser(); }
public ActionResult DeleteConfirmed(int id) { var user = db.Users.Find(id); db.Users.Remove(user); try { db.SaveChanges(); UsersHelpers. DeleteUser(user.UserName); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException. InnerException != null && ex.InnerException. InnerException.Message. Contains("REFERENCE")) { ModelState. AddModelError( string.Empty, "The Selected Record can't be Deleted, " + " Because it Already Contains Related Records"); } else { ModelState. AddModelError( string.Empty, ex.Message); } } return(View(user)); }
public ActionResult DeleteConfirmed(int id) { var user = db.Users.Find(id); db.Users.Remove(user); var response = DBHelpers.SaveChanges(db); if (response.Succeeded) { UsersHelpers. DeleteUser(user.UserName); return(RedirectToAction("Index")); } ModelState.AddModelError( string.Empty, response.Message); return(View(user)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); var response = DBHelpers.SaveChanges(db); if (response.Succeeded) { UsersHelpers. CreateUserASP(user.UserName, "User"); if (user.PhotoFile != null) { var folder = "~/Content/Photos"; var file = string.Format("{0}.jpg", user.UserID); var response0 = FilesHelpers. UploadPhoto( user.PhotoFile, folder, file); if (response0) { var pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ModelState.AddModelError( string.Empty, response.Message); } ViewBag.CityId = new SelectList( ComboBoxHelpers. GetCities(user.StateId), "CityId", "NameCity", user.CityId); ViewBag.CompanyId = new SelectList( ComboBoxHelpers. GetCompanies(), "CompanyId", "NameCompany", user.CompanyId); ViewBag.StateId = new SelectList( ComboBoxHelpers. GetStates(), "StateId", "NameState", user.StateId); return(View(user)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); try { db.SaveChanges(); UsersHelpers. CreateUserASP(user.UserName, "User"); if (user.PhotoFile != null) { var folder = "~/Content/Photos"; var file = string.Format("{0}.jpg", user.UserID); var response = FilesHelpers. UploadPhoto( user.PhotoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException. InnerException != null && ex.InnerException. InnerException.Message. Contains("_Index")) { ModelState. AddModelError( string.Empty, "You Can't Add a New Record, Because There is Already One"); } else { ModelState. AddModelError( string.Empty, ex.Message); } } } ViewBag.CityId = new SelectList( ComBoxHelpers. GetCities(), "CityId", "NameCity", user.CityId); ViewBag.CompanyId = new SelectList( ComBoxHelpers. GetCompanies(), "CompanyId", "NameCompany", user.CompanyId); ViewBag.StateId = new SelectList( ComBoxHelpers. GetStates(), "StateId", "NameState", user.StateId); return(View(user)); }
protected with_the_actionLogs_service() { _actionLogsRepositoryMock = new Mock <IActionLogsRepository>(); _departmentMembersRepositoryMock = new Mock <IDepartmentMembersRepository>(); _usersServiceMock = new Mock <IUsersService>(); _departmentGroupsServiceMock = new Mock <IDepartmentGroupsService>(); _departmentsServiceMock = new Mock <IDepartmentsService>(); _departmentSettingsServiceMock = new Mock <IDepartmentSettingsService>(); _eventAggregatorMock = new Mock <IEventAggregator>(); _geoServiceMock = new Mock <IGeoService>(); _customStateServiceMock = new Mock <ICustomStateService>(); _cacheProviderMock = new Mock <ICacheProvider>(); DepartmentMembershipHelpers.SetupDisabledAndHiddenUsers(_departmentsServiceMock); _actionLogsRepositoryMock.Setup(m => m.GetAllAsync()).ReturnsAsync(ActionLogsHelpers.CreateActionLogsForDepartment4()); _departmentMembersRepositoryMock.Setup(m => m.GetAllAsync()).ReturnsAsync(DepartmentMembershipHelpers.CreateDepartmentMembershipsForDepartment4()); _departmentsServiceMock.Setup(m => m.GetAllMembersForDepartmentAsync(4)).ReturnsAsync(DepartmentMembershipHelpers.CreateDepartmentMembershipsForDepartment4().ToList()); _usersServiceMock.Setup(m => m.GetUserById(It.IsAny <string>(), true)).Returns((string v) => UsersHelpers.CreateUser(v)); _actionLogsService = Resolve <IActionLogsService>(); _actionLogsServiceMocked = new ActionLogsService(_actionLogsRepositoryMock.Object, _usersServiceMock.Object, _departmentMembersRepositoryMock.Object, _departmentGroupsServiceMock.Object, _departmentsServiceMock.Object, _departmentSettingsServiceMock.Object, _eventAggregatorMock.Object, _geoServiceMock.Object, _customStateServiceMock.Object, _cacheProviderMock.Object); }