public static Field GetFieldByName(int categoryId, string name) { using (var context = new ShedEntities()) { return(context.Fields.SingleOrDefault(f => f.CategoryId == categoryId && f.Label == name)); } }
public static void AddNew(Field field) { using (var context = new ShedEntities()) { field.Label = field.Label.Trim(); if (!NameInUse(context, field.CategoryId, field.Label)) { context.Fields.InsertOnSubmit(field); context.SubmitChanges(); var credentials = new List <Credential>(); foreach (Account account in AccountService.GetAccountsByCategoryId(field.CategoryId)) { credentials.Add (new Credential { AccountId = account.Id, Created = DateTime.Now, FieldId = field.Id }); } CredentialService.AddNew(context, credentials); context.SubmitChanges(); } else { throw new ArgumentException("A field with this name already exists."); } } }
public static Credential GetCredential(int credentialId) { using (var context = new ShedEntities()) { return(context.Credentials.SingleOrDefault(c => c.Id == credentialId)); } }
public static void DeleteByFieldId(ShedEntities context, int fieldId) { var credentials = context.Credentials.Where(c => c.FieldId == fieldId); context.Credentials.DeleteAllOnSubmit(credentials); context.SubmitChanges(); }
public static void AddNew(MasterPassword password) { using (var context = new ShedEntities()) { context.MasterPasswords.InsertOnSubmit(password); context.SubmitChanges(); } }
public static void DeleteByCategoryId(ShedEntities context, int categoryId) { var credentials = from c in context.Credentials join a in context.Accounts on c.AccountId equals a.Id where a.CategoryId == categoryId select c; context.Credentials.DeleteAllOnSubmit(credentials); }
public static void Update(int accountId, int fieldId, string value) { using (var context = new ShedEntities()) { var credential = context.Credentials.SingleOrDefault(c => c.AccountId == accountId && c.FieldId == fieldId); credential.Value = value.Trim(); credential.Modified = DateTime.Now; context.SubmitChanges(); } }
public static void Update(int id, int displayIndex) { using (var context = new ShedEntities()) { var field = context.Fields.SingleOrDefault(f => f.Id == id); field.DisplayIndex = displayIndex; context.SubmitChanges(); } }
public static List <Field> GetFieldsByCategoryId(int categoryId) { var fields = new List <Field>(); using (var context = new ShedEntities()) { fields.AddRange(context.Fields.Where(f => f.CategoryId == categoryId)); } return(fields); }
public static void Delete(int id) { using (var context = new ShedEntities()) { context.Categories.DeleteOnSubmit(context.Categories.SingleOrDefault(c => c.Id == id)); AccountService.DeleteByCategoryId(context, id); FieldService.DeleteByCategoryId(context, id); CredentialService.DeleteByCategoryId(context, id); context.SubmitChanges(); } }
public static void DeleteAccountsWithoutCredentials(ShedEntities context) { foreach (Account account in context.Accounts) { if (!context.Credentials.Any(c => c.AccountId == account.Id)) { context.Accounts.DeleteOnSubmit(account); context.SubmitChanges(); } } }
public static List <Category> GetAllCategories() { var allCategories = new List <Category>(); using (var context = new ShedEntities()) { allCategories.AddRange(context.Categories); } return(allCategories); }
public static void Delete(int accountId) { using (var context = new ShedEntities()) { var account = context.Accounts.SingleOrDefault(a => a.Id == accountId); context.Accounts.DeleteOnSubmit(account); CredentialService.DeleteByAccountId(context, accountId); context.SubmitChanges(); } }
public static List <Account> GetAccountsByCategoryId(int categoryId) { var accountsInCategory = new List <Account>(); using (var context = new ShedEntities()) { accountsInCategory.AddRange(context.Accounts.Where(a => a.CategoryId == categoryId)); } return(accountsInCategory); }
public static List <Credential> GetCredentialsByAccountId(int accountId) { var credentialsInCategory = new List <Credential>(); using (var context = new ShedEntities()) { credentialsInCategory.AddRange(context.Credentials.Where(c => c.AccountId == accountId)); } return(credentialsInCategory); }
public static void Delete(int id) { using (var context = new ShedEntities()) { var field = context.Fields.SingleOrDefault(f => f.Id == id); context.Fields.DeleteOnSubmit(field); CredentialService.DeleteByFieldId(context, id); AccountService.DeleteAccountsWithoutCredentials(context); context.SubmitChanges(); } }
public static string GetPasswordHash() { using (var context = new ShedEntities()) { var password = context.MasterPasswords.FirstOrDefault(); if (password != null) { return(password.PasswordHash); } return(""); } }
public static void AddNew(Category category) { using (var context = new ShedEntities()) { category.Label = category.Label.Trim(); if (!NameInUse(context, category.Label)) { context.Categories.InsertOnSubmit(category); context.SubmitChanges(); } else { throw new ArgumentException("A category with this name already exists."); } } }
public static void Update(int id, string name) { using (var context = new ShedEntities()) { name = name.Trim(); if (!NameInUse(context, name)) { var category = context.Categories.SingleOrDefault(c => c.Id == id); category.Label = name; context.SubmitChanges(); } else { throw new ArgumentException("A category with this name already exists."); } } }
public static void Update(int id, string name) { using (var context = new ShedEntities()) { name = name.Trim(); var field = context.Fields.SingleOrDefault(f => f.Id == id); if (!NameInUse(context, field.CategoryId, name)) { field.Label = name; context.SubmitChanges(); } else { throw new ArgumentException("A field with this name already exists."); } } }
private void ButtonOn_Click() { using (ShedEntities db = new ShedEntities()) { var classroms = db.Classrooms.ToList(); int maxNumberOfSeatsOfClassrooms = classroms.Max(x => x.NumberOfSeats); var unionsGroups = new UnionsGroups(db.Groups.ToList(), maxNumberOfSeatsOfClassrooms); TextBoxMaxClassroom.Text = $"Max classrooms={classroms.Max(x=>x.NumberOfSeats)}"; TextBoxUnionAll.Text = $"{unionsGroups}"; var unionsGroupsSeminar = unionsGroups.FilterUnionGroups(FilterSeminar); TextBoxUnionFilterSeminar.Text = $"{unionsGroupsSeminar}"; var unionsGroupsPotok = unionsGroups.FilterUnionGroups(FilterPotok); TextBoxUnionFilterPotok.Text = $"{unionsGroupsPotok}"; } }
public static int AddNewWithBlankCredentials(Account account) { using (var context = new ShedEntities()) { context.Accounts.InsertOnSubmit(account); context.SubmitChanges(); var credentials = new List <Credential>(); foreach (var field in context.Fields.Where(f => f.CategoryId == account.CategoryId)) { credentials.Add(new Credential { AccountId = account.Id, FieldId = field.Id, Created = DateTime.Now }); } CredentialService.AddNew(context, credentials); context.SubmitChanges(); } return(account.Id); }
public static void DeleteByCategoryId(ShedEntities context, int categoryId) { var accounts = context.Accounts.Where(a => a.CategoryId == categoryId); context.Accounts.DeleteAllOnSubmit(accounts); }
private static bool NameInUse(ShedEntities context, string name) { return(context.Categories.Any(c => c.Label == name)); }
public static void DeleteByAccountId(ShedEntities context, int accountId) { var credentials = context.Credentials.Where(c => c.AccountId == accountId); context.Credentials.DeleteAllOnSubmit(credentials); }
public static void AddNew(ShedEntities context, List <Credential> credentials) { context.Credentials.InsertAllOnSubmit(credentials); }
public static void DeleteByCategoryId(ShedEntities context, int categoryId) { var fields = context.Fields.Where(f => f.CategoryId == categoryId); context.Fields.DeleteAllOnSubmit(fields); }
private static bool NameInUse(ShedEntities context, int categoryId, string name) { return(context.Fields.Any(f => f.Label == name && f.CategoryId == categoryId)); }