public static void AddCompany(Company company) { using (var context = new ClientBaseContext()) { context.Companies.Add(company); context.SaveChanges(); } }
public static void AddUser(User user) { using (var context = new ClientBaseContext()) { context.Users.Add(user); context.SaveChanges(); } }
public static IEnumerable <Company> GetAllCompanies() { IEnumerable <Company> companies = null; using (var context = new ClientBaseContext()) companies = context.Companies.ToArray(); return(companies); }
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); }
public static IEnumerable <User> GetAllUsers() { IEnumerable <User> users = null; using (var context = new ClientBaseContext()) users = context.Users.ToArray(); return(users); }
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(); } }
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(); } }
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(); } }
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(); } }