public static void CreateNewFilter(SearchFilterInfo createSearchFilterInfo, out string error) { try { using (var ctx = new BotContext()) { var all = ctx.SearchFilterInfos; if (all.Any()) { var existing = ctx.SearchFilterInfos.ToList(); if (existing.Any(x => x.FilterName == createSearchFilterInfo.FilterName)) { error = "Фильтр с таким именем уже существует"; return; } } ctx.SearchFilterInfos.Add(createSearchFilterInfo); ctx.SaveChanges(); } error = ""; } catch (System.Exception e) { error = e.Message; } }
public static void ChangeLoginPassword(string login, string password, out string error) { try { using (var ctx = new BotContext()) { var entity = ctx.LoginPasswords.FirstOrDefault(x => x.Login == login); if (entity == null) { error = "Логин : " + login + " отсутствует."; return; } entity.Password = password; ctx.SaveChanges(); } error = ""; } catch (System.Exception e) { error = e.Message; } }
public static void CreateLoginPassword(string login, string password, out string error) { try { using (var ctx = new BotContext()) { var existEntity = ctx.LoginPasswords.FirstOrDefault(x => x.Login == login); if (existEntity != null) { error = "Логин : " + login + " уже существует."; return; } var entity = new BotLoginPassword() { Login = login, Password = password, }; ctx.LoginPasswords.Add(entity); ctx.SaveChanges(); } error = ""; } catch (System.Exception e) { error = e.Message; } }
public static List <KeyValuePair <string, string> > GetAllLoginsPasswords() { using (var ctx = new BotContext()) { var entities = ctx.LoginPasswords; if (entities.Any()) { return(entities.ToList().Select(x => new KeyValuePair <string, string>(x.Login, x.Password)).ToList()); } return(new List <KeyValuePair <string, string> >()); } }
public static List <SearchFilterInfo> GetAllSearchFilters(out string error) { try { using (var ctx = new BotContext()) { error = ""; return(ctx.SearchFilterInfos.ToList()); } } catch (System.Exception e) { error = e.Message; return(null); } }