コード例 #1
0
 public static void AddCompany(Company company)
 {
     using (var context = new ClientBaseContext())
     {
         context.Companies.Add(company);
         context.SaveChanges();
     }
 }
コード例 #2
0
 public static void AddUser(User user)
 {
     using (var context = new ClientBaseContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
コード例 #3
0
        public static IEnumerable <Company> GetAllCompanies()
        {
            IEnumerable <Company> companies = null;

            using (var context = new ClientBaseContext())
                companies = context.Companies.ToArray();

            return(companies);
        }
コード例 #4
0
        public static IEnumerable <User> GetUsersByCompany(Company company)
        {
            IEnumerable <User> users = null;

            using (var context = new ClientBaseContext())
                users = context.Users.Where(u => u.CompanyId == company.Id).ToArray();

            return(users);
        }
コード例 #5
0
        public static IEnumerable <User> GetAllUsers()
        {
            IEnumerable <User> users = null;

            using (var context = new ClientBaseContext())
                users = context.Users.ToArray();

            return(users);
        }
コード例 #6
0
        public static void UpdateCompany(Company company)
        {
            using (var context = new ClientBaseContext())
            {
                var companyEntity = context.Companies.Find(company.Id);

                context.Entry(companyEntity).CurrentValues.SetValues(company);
                context.SaveChanges();
            }
        }
コード例 #7
0
        public static void UpdateUser(User user)
        {
            using (var context = new ClientBaseContext())
            {
                var userEntity = context.Users.Find(user.Id);

                context.Entry(userEntity).CurrentValues.SetValues(user);
                context.SaveChanges();
            }
        }
コード例 #8
0
        public static void DeleteUser(User user)
        {
            using (var context = new ClientBaseContext())
            {
                var userEntity = context.Users.First(u => u.Id == user.Id);

                context.Users.Remove(userEntity);
                context.SaveChanges();
            }
        }
コード例 #9
0
        public static void DeleteCompany(Company company)
        {
            using (var context = new ClientBaseContext())
            {
                var companyEntity = context.Companies.First(c => c.Id == company.Id);

                context.Users.RemoveRange(companyEntity.Users);
                context.Companies.Remove(companyEntity);

                context.SaveChanges();
            }
        }