Ejemplo n.º 1
0
 public static Field GetFieldByName(int categoryId, string name)
 {
     using (var context = new ShedEntities())
     {
         return(context.Fields.SingleOrDefault(f => f.CategoryId == categoryId && f.Label == name));
     }
 }
Ejemplo n.º 2
0
        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.");
                }
            }
        }
Ejemplo n.º 3
0
 public static Credential GetCredential(int credentialId)
 {
     using (var context = new ShedEntities())
     {
         return(context.Credentials.SingleOrDefault(c => c.Id == credentialId));
     }
 }
Ejemplo n.º 4
0
        public static void DeleteByFieldId(ShedEntities context, int fieldId)
        {
            var credentials = context.Credentials.Where(c => c.FieldId == fieldId);

            context.Credentials.DeleteAllOnSubmit(credentials);
            context.SubmitChanges();
        }
Ejemplo n.º 5
0
 public static void AddNew(MasterPassword password)
 {
     using (var context = new ShedEntities())
     {
         context.MasterPasswords.InsertOnSubmit(password);
         context.SubmitChanges();
     }
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 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();
     }
 }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 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();
     }
 }
Ejemplo n.º 11
0
 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();
         }
     }
 }
Ejemplo n.º 12
0
        public static List <Category> GetAllCategories()
        {
            var allCategories = new List <Category>();

            using (var context = new ShedEntities())
            {
                allCategories.AddRange(context.Categories);
            }

            return(allCategories);
        }
Ejemplo n.º 13
0
        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();
            }
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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();
            }
        }
Ejemplo n.º 17
0
        public static string GetPasswordHash()
        {
            using (var context = new ShedEntities())
            {
                var password = context.MasterPasswords.FirstOrDefault();

                if (password != null)
                {
                    return(password.PasswordHash);
                }

                return("");
            }
        }
Ejemplo n.º 18
0
        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.");
                }
            }
        }
Ejemplo n.º 19
0
        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.");
                }
            }
        }
Ejemplo n.º 20
0
        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}";
            }
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        public static void DeleteByCategoryId(ShedEntities context, int categoryId)
        {
            var accounts = context.Accounts.Where(a => a.CategoryId == categoryId);

            context.Accounts.DeleteAllOnSubmit(accounts);
        }
Ejemplo n.º 24
0
 private static bool NameInUse(ShedEntities context, string name)
 {
     return(context.Categories.Any(c => c.Label == name));
 }
Ejemplo n.º 25
0
        public static void DeleteByAccountId(ShedEntities context, int accountId)
        {
            var credentials = context.Credentials.Where(c => c.AccountId == accountId);

            context.Credentials.DeleteAllOnSubmit(credentials);
        }
Ejemplo n.º 26
0
 public static void AddNew(ShedEntities context, List <Credential> credentials)
 {
     context.Credentials.InsertAllOnSubmit(credentials);
 }
Ejemplo n.º 27
0
        public static void DeleteByCategoryId(ShedEntities context, int categoryId)
        {
            var fields = context.Fields.Where(f => f.CategoryId == categoryId);

            context.Fields.DeleteAllOnSubmit(fields);
        }
Ejemplo n.º 28
0
 private static bool NameInUse(ShedEntities context, int categoryId, string name)
 {
     return(context.Fields.Any(f => f.Label == name && f.CategoryId == categoryId));
 }