You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.9 KiB
101 lines
2.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
namespace eCompanies
|
|
{
|
|
/// <summary>
|
|
/// Логика взаимодействия для App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
public static ObservableCollection<Company> getCompanies()
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
return new ObservableCollection<Company>(db.Company.AsEnumerable());
|
|
}
|
|
|
|
public static HashSet<Users> getUsers(int id)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
return new HashSet<Users>(db.Users.Where(b => b.CompanyId.Equals(id)));
|
|
}
|
|
|
|
public static void addCompany(Company c)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
{
|
|
db.Company.Add(c);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public static void updateCompany(Company c)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
{
|
|
db.Company.Update(c);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public static void updateCompany1(Company c)
|
|
{
|
|
//using (var db = new CompaniesDBContext())
|
|
//{
|
|
// var x = db.Company.Where(i => i.CompanyId.Equals(c.CompanyId));
|
|
// foreach (Company t in x) t = c;
|
|
//}
|
|
}
|
|
|
|
public static void removeCompany(int id)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
{
|
|
var x = db.Company.Where(i => i.CompanyId.Equals(id));
|
|
foreach (Company c in x) db.Company.Remove(c);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public static void removeCompany(List<int> idList)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
{
|
|
foreach (int id in idList)
|
|
{
|
|
var x = db.Company.Where(i => i.CompanyId.Equals(id));
|
|
foreach (Company c in x) db.Company.Remove(c);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public static void removeUser(int id)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
{
|
|
var x = db.Users.Where(i => i.UserId.Equals(id));
|
|
foreach (Users u in x) db.Users.Remove(u);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public static void removeUser(List<int> idList)
|
|
{
|
|
using (var db = new CompaniesDBContext())
|
|
{
|
|
foreach (int id in idList)
|
|
{
|
|
var x = db.Users.Where(i => i.UserId.Equals(id));
|
|
foreach (Users u in x) db.Users.Remove(u);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|