public void WriteSettings(ViewModels.UsersGroupsSettingsVM settings) { foreach (var singlerecord in settings.ExtendedUsersGroupsListVM) { if (singlerecord.Delete) { if (!TryDelete(singlerecord.Id)) { _orchardServices.Notifier.Add(NotifyType.Error, T("Group user is in use and can't be deleted")); } else { ExtendedUsersGroupsRecord ex = new ExtendedUsersGroupsRecord(); ex.Id = singlerecord.Id; ex.GroupName = singlerecord.GroupName; this.DeleteGroup(ex); } } else { ExtendedUsersGroupsRecord ex = new ExtendedUsersGroupsRecord(); ex.Id = singlerecord.Id; ex.GroupName = singlerecord.GroupName; this.UpdateGroup(ex); } } }
public ViewModels.UsersGroupsSettingsVM ReadSettings() { var settings = new ViewModels.UsersGroupsSettingsVM(); settings.ExtendedUsersGroupsListVM = new List <ViewModels.ExtendedUsersGroupsRecordVM>(); var tab = _extendedUsersGroupsRepository.Table.OrderBy(o => o.GroupName).ToList(); foreach (var record in tab) { ViewModels.ExtendedUsersGroupsRecordVM evm = new ViewModels.ExtendedUsersGroupsRecordVM(); evm.Id = record.Id; evm.GroupName = record.GroupName; settings.ExtendedUsersGroupsListVM.Add(evm); } return(settings); }
public ActionResult Settings(ViewModels.UsersGroupsSettingsVM model) { if (!_orchardServices.Authorizer.Authorize(OrchardCore.Settings.Permissions.ManageSettings, T("You don't have permission \"Manage settings\" to define and manage User Groups!"))) { return(new HttpUnauthorizedResult()); } if (!ModelState.IsValid) { _orchardServices.Notifier.Error(T("Settings update failed: {0}", T("check your input!"))); return(View(model)); } try { _usersGroupsSettingsService.WriteSettings(model); _orchardServices.Notifier.Information(T("Settings updated.")); // I read again my model in order to its ids model = _usersGroupsSettingsService.ReadSettings(); } catch (Exception exception) { _orchardServices.Notifier.Error(T("Settings update failed: {0}", exception.Message)); } return(RedirectToActionPermanent("Settings")); }