public CustomList(ulong ownerId, ListPermission permission, String name) { this.OwnerId = ownerId; this.Permission = permission; this.Name = name; Contents = new List <string>(); }
private ListOutput CreateList(UserInfo userInfo, ListPermission listPermissions, params string[] input) { if (input.Length == 0 || input.Length > 2) { throw GetListManagerException(ListErrorMessage.General.WrongFormat); } var listName = input[0]; try { GetList(listName); } catch (ListManagerException) { var newList = new CustomList(dataStorage, userInfo, listPermissions, listName); newList.SaveList(); Lists.Add(newList); WriteContents(); var permissionAsString = PermissionStrings[(int)listPermissions]; return(GetListOutput($"Created {permissionAsString} list '{listName}'", listPermissions)); } throw GetListManagerException(ListErrorMessage.General.ListAlreadyExists_list, listName); }
private void ClickEdit(object sender, RoutedEventArgs e) { switch (SelectedObj) { case 1: Student x = theObj as Student; NewStudent win6 = new NewStudent(label.Content.ToString(), x.Id); win6.deligEven += (s, t) => refreshMyView(); win6.Show(); break; case 2: Teacher y = theObj as Teacher; NewTeacher win7 = new NewTeacher(label.Content.ToString(), y.Id); win7.deligEven += (s, t) => refreshMyView(); win7.Show(); break; case 3: MeetTest z = theObj as MeetTest; NewMeetTest win8 = new NewMeetTest(label.Content.ToString(), z.TestId.ToString()); win8.deligEven += (s, t) => refreshMyView(); win8.Show(); break; case 4: ListPermission u = theObj as ListPermission; UserPermissen win9 = new UserPermissen(label.Content.ToString(), u.Id); win9.deligEven += (s, t) => refreshMyView(); win9.Show(); break; } }
public CustomList(IDataStorage dataStorage, UserInfo userInfo, ListPermission permission, String name) { this.dataStorage = dataStorage; this.OwnerId = userInfo.Id; this.Name = name; if (userInfo.RoleIds != null) { PermissionByRole.Add(userInfo.RoleIds.First(), permission); } Contents = new List <string>(); }
/// <summary> /// check for all permission of user if there is apropriate permission to action /// </summary> /// <param name="hash">user code</param> /// <param name="op">action code</param> /// <param name="x">object gruops</param> public static void HashToAcsess(string hash, int op, List <string> x) { string id = DL.Dal_imp.Instance.idByToken(hash); ListPermission L = DL.Dal_imp.Instance.ListpermissById(id); foreach (permission P in L.permisses) { if (permiitionOnListPermittion(x, P) && acsessToFunc(op, P)) { return; } } throw new Exception("acsess deined"); }
/// <summary> /// cerate Standart listPermition to User. /// 1. if exist Teacher on his id, create teacher permission. /// </summary> /// <param name="id"></param> /// <returns></returns> private ListPermission addStandartPermission(string id) { bool[] per; try { ShowTeacher(id); per = def.TeacherForHisTests.Clone() as bool[]; } catch { per = def.NewIdGroup.Clone() as bool[]; } ListPermission temp = new ListPermission(id, new permission(id, per)); permiss.Add(temp); return(permiss[permiss.IndexOf(temp)]); }
//public IDataStorage DataStorage //{ // get { return DataStorage; } // set { DataStorage = DataStorage ?? value; } //} //private readonly DiscordSocketClient client; public CustomList(IDataStorage dataStorage, UserInfo userInfo, ListPermission permission, String name) { this.dataStorage = dataStorage; this.OwnerId = userInfo.Id; //this.Permission = permission; this.Name = name; //RoleEveryone = this.client.Guilds.FirstOrDefault().EveryoneRole.Name; if (userInfo.RoleIds != null) { //RoleEveryoneId = userInfo.RoleIds.First(); PermissionByRole.Add(userInfo.RoleIds.First(), permission); } Contents = new List <string>(); }
public bool SetPermissionByRole(ulong roleId, ListPermission permission) { if (PermissionByRole.ContainsKey(roleId)) { if (PermissionByRole[roleId] == permission) { return(false); } PermissionByRole[roleId] = permission; } else { PermissionByRole.Add(roleId, permission); } SaveList(); return(true); }
public List <ListPermission> ShowPermission() { DapperHelper <PermissionTableModel> per = new DapperHelper <PermissionTableModel>(); string sql = "select * from PermissionTable where Permission_Pid=0"; List <PermissionTableModel> m = per.Query(sql); ListPermission lp = new ListPermission(); List <ListPermission> list = new List <ListPermission>(); foreach (PermissionTableModel model in m) { ListPermission pr = new ListPermission { Id = model.Id, Permission_Name = model.Permission_Name, Permission_Pid = model.Permission_Pid, ModelList = per.Query("select * from PermissionTable where Permission_Pid=" + model.Id) }; list.Add(pr); } return(list); }
private ListOutput OutputList(UserInfo userInfo, ListPermission permission, params string[] input) { if (input.Length != 1) { throw GetListManagerException(ListErrorMessage.General.WrongFormat); } CustomList list = GetList(input[0]); ThrowIfMissingReadPermission(userInfo, list); if (list.Count() == 0) { throw GetListManagerException(ListErrorMessage.General.ListIsEmpty_list, input[0]); } Func <int, int, int> GetLonger = (i1, i2) => { return(i1 > i2 ? i1 : i2); }; var maxItemLength = 0; var values = new string[list.Count(), 1]; for (int i = 0; i < list.Count(); i++) { var row = $"{(i + 1).ToString()}: {list.Contents[i]}"; values[i, 0] = row; maxItemLength = GetLonger(maxItemLength, row.Length); } maxItemLength = GetLonger(maxItemLength, list.Name.Length); var tableSettings = new MessageFormater.TableSettings(list.Name, -(maxItemLength), false); string output = MessageFormater.CreateTable(tableSettings, values); var outputPermission = permission == ListPermission.PRIVATE ? list.PermissionByRole.First().Value : permission; return(GetListOutput(output, outputPermission)); }
public static ListOutput GetListOutput(Discord.Embed e, ListPermission p) { return(new ListOutput { outputEmbed = e, permission = p }); }
public static ListOutput GetListOutput(string s, ListPermission p) { return(new ListOutput { outputString = s, permission = p }); }
private ListOutput GetAll(UserInfo userInfo, ListPermission outputPermission) { if (Lists.Count == 0) { throw GetListManagerException(ListErrorMessage.General.NoLists); } Func <int, int, int> GetLonger = (i1, i2) => { return(i1 > i2 ? i1 : i2); }; var tableValuesList = new Dictionary <String, String>(); for (int i = 0; i < Lists.Count; i++) { CustomList l = Lists[i]; if (l.IsAllowedToList(userInfo)) { tableValuesList.Add(l.Name, $"{l.Count()} {GetNounPlural("item", l.Count())}"); } } var maxItemLength = 0; var tableValues = new string[tableValuesList.Count, 2]; for (int i = 0; i < tableValues.GetLength(0); i++) { var keyPair = tableValuesList.ElementAt(i); tableValues[i, 0] = keyPair.Key; tableValues[i, 1] = keyPair.Value; maxItemLength = GetLonger(maxItemLength, keyPair.Key.Length); maxItemLength = GetLonger(maxItemLength, keyPair.Value.Length); } var header = new[] { "List name", "Item count" }; foreach (string s in header) { maxItemLength = GetLonger(maxItemLength, s.Length); } var tableSettings = new MessageFormater.TableSettings("All lists", header, -(maxItemLength), true); string output = MessageFormater.CreateTable(tableSettings, tableValues); var count = 0; for (int i = 0; i < output.Length; i++) { if (output[i] == '\n') { if (count == 8) { output = output.Insert(i, LineIndicator); break; } else { count++; } } } var returnValue = GetListOutput(output, outputPermission); returnValue.listenForReactions = true; return(returnValue); }