public Brand GetBrandByBrandID(long BrandID) { CompanyDBContext db = new CompanyDBContext(); Brand existingBrand = db.Brands.Where(temp => temp.BrandID == BrandID).FirstOrDefault(); return(existingBrand); }
public List <Brand> Get() { CompanyDBContext db = new CompanyDBContext(); List <Brand> brands = db.Brands.ToList(); return(brands); }
private static DepartmentService GetDepartmentServiceInstance() { var context = new CompanyDBContext(); var deptService = new DepartmentService(context); return(deptService); }
// GET: Admin/Categories public ActionResult Index() { CompanyDBContext db = new CompanyDBContext(); List <Category> categories = db.Categories.ToList(); return(View(categories)); }
public List <Categorie> GetListCategorie() { var context = new CompanyDBContext(); var list = context.Categories.ToList(); return(list); }
// GET: Products public ActionResult Index() { CompanyDBContext db = new CompanyDBContext(); List <Product> products = db.Products.ToList(); return(View(products)); }
public void PostBrand(Brand newBrand) { CompanyDBContext db = new CompanyDBContext(); db.Brands.Add(newBrand); db.SaveChanges(); }
public void PutBrand(Brand brandData) { CompanyDBContext db = new CompanyDBContext(); var existingBrand = db.Brands.Where(temp => temp.BrandID == brandData.BrandID).FirstOrDefault(); existingBrand.BrandName = brandData.BrandName; db.SaveChanges(); }
public Order GetOrder(int Id) { using (var CompanyDBContext = new CompanyDBContext()) { Order order = CompanyDBContext.Set <Order>().FirstOrDefault(o => o.Id == Id); return(order); } }
public void DeleteBrand(long BrandID) { CompanyDBContext db = new CompanyDBContext(); var existingBrand = db.Brands.Where(temp => temp.BrandID == BrandID).FirstOrDefault(); db.Brands.Remove(existingBrand); db.SaveChanges(); }
public void RemoveEntity <T>(T Entity) where T : class { using (var CompanyDBContext = new CompanyDBContext()) { CompanyDBContext.Set <T>().Remove(Entity); CompanyDBContext.SaveChanges(); } }
public ICollection <Gender> GetGenders() { using (var CompanyDBContext = new CompanyDBContext()) { List <Gender> genders = CompanyDBContext.Set <Gender>().ToList(); return(genders); } }
public void UpdateOrder(Order Entity) { using (var CompanyDBContext = new CompanyDBContext()) { var OldEntity = CompanyDBContext.Set <Order>().Find(Entity.Id); OldEntity.Name = Entity.Name; CompanyDBContext.SaveChanges(); } }
public Worker GetWorker(int Id) { using (var CompanyDBContext = new CompanyDBContext()) { Worker worker = CompanyDBContext.Set <Worker>().FirstOrDefault(w => w.Id == Id); worker.BossOfDepartment = CompanyDBContext.Set <Department>().FirstOrDefault(d => d.BossId == worker.Id); return(worker); } }
public Gender GetGender(int IdGender) { using (var CompanyDBContext = new CompanyDBContext()) { Gender gender = CompanyDBContext.Set <Gender>().FirstOrDefault(g => g.Id == IdGender); return(gender); } }
public void TestOnDelete() { var mockSet = GenerateMock(); var mockContext = new Mock <CompanyDBEntities>(); mockContext.Setup(m => m.Companies).Returns(mockSet.Object); var companyContext = new CompanyDBContext(mockContext.Object); companyContext.DeleteCompany(companyContext.FindCompanyById(1)); mockSet.Verify(m => m.Remove(It.IsAny <Company>()), Times.Once()); }
public ICollection <Order> GetOrders(int workId) { using (var CompanyDBContext = new CompanyDBContext()) { List <Order> orders = CompanyDBContext.Set <Order>().Where(o => o.WorkerId == workId).ToList(); for (int i = 0; i < orders.Count(); i++) { Order order = orders[i]; } return(orders); } }
public void UpdateWorker(Worker Entity) { using (var CompanyDBContext = new CompanyDBContext()) { var OldEntity = CompanyDBContext.Set <Worker>().Find(Entity.Id); OldEntity.Name = Entity.Name; OldEntity.Surname = Entity.Surname; OldEntity.Middlename = Entity.Middlename; OldEntity.DepartmentId = Entity.Department.Id; OldEntity.Birthday = Entity.Birthday; OldEntity.GenderId = Entity.Gender.Id; CompanyDBContext.SaveChanges(); } }
public void TestIfCompanyExistById() { var mockSet = GenerateMock(); var mockContext = new Mock <CompanyDBEntities>(); mockContext.Setup(m => m.Companies).Returns(mockSet.Object); var companyContext = new CompanyDBContext(mockContext.Object); var comp = companyContext.GetCompanyById(1); var findComp = companyContext.FindCompanyById(1); Assert.AreEqual(1, findComp.CompanyId); Assert.AreEqual(1, comp.Count); Assert.AreEqual(1, comp[0].CompanyId); }
public void TestGetCompanies() { var mockSet = GenerateMock(); var mockContext = new Mock <CompanyDBEntities>(); mockContext.Setup(m => m.Companies).Returns(mockSet.Object); var companyContext = new CompanyDBContext(mockContext.Object); var comp = companyContext.GetAllCompanies().ToList(); Assert.AreEqual(3, comp.Count); Assert.AreEqual(1, comp[0].CompanyId); Assert.AreEqual(2, comp[1].CompanyId); Assert.AreEqual(3, comp[2].CompanyId); }
public ICollection <Worker> GetWorkers(int depId) { using (var CompanyDBContext = new CompanyDBContext()) { List <Worker> workers = CompanyDBContext.Set <Worker>().Where(w => w.DepartmentId == depId).ToList(); for (int i = 0; i < workers.Count(); i++) { Worker worker = workers[i]; worker.Gender = GetGender(worker.GenderId); worker.Orders = GetOrders(worker.Id); } return(workers); } }
public void TestIfCompanyExistOnAdd() { var mockSet = new Mock <DbSet <Company> >(); var mockContext = new Mock <CompanyDBEntities>(); mockContext.Setup(m => m.Companies).Returns(mockSet.Object); var companyContext = new CompanyDBContext(mockContext.Object); companyContext.AddCompany(new Company() { CompanyId = 1, CompanyName = "Test", Email = "*****@*****.**", LastName = "Testing", PhoneNumber = 123456 }); mockSet.Verify(m => m.Add(It.IsAny <Company>()), Times.Once()); }
public Department GetDepartment(int Id) { using (var CompanyDBContext = new CompanyDBContext()) { Department department = CompanyDBContext.Set <Department>().ToList().FirstOrDefault(d => d.Id == Id); department.Workers = GetWorkers(department.Id); if (department.BossId.HasValue) { department.Boss = department.Workers.FirstOrDefault(w => w.Id == department.BossId); } return(department); } }
public EmployeesViewModel(Employee employee, CompanyDBContext context) { EmployeeView = employee; var dept = context.Departments.Find(employee.DepartmentId); if (null == dept) { Dept = new Department() { Name = "UnAssigned", Description = "PlaceHolder for not existing department" }; } else { Dept = dept; } }
public void TestIfDetailsUpdated() { var mockSet = GenerateMock(); var mockContext = new Mock <CompanyDBEntities>(); mockContext.Setup(m => m.Companies).Returns(mockSet.Object); var companyContext = new CompanyDBContext(mockContext.Object); //Get a company by Id var firstComp = companyContext.FindCompanyById(1); firstComp.CompanyName = "Updated Company"; //Get a list of companies var comp = companyContext.GetCompanyById(1); Assert.AreEqual("Updated Company", comp[0].CompanyName); //Updated data }
public ICollection <Department> GetDepartments() { using (var CompanyDBContext = new CompanyDBContext()) { List <Department> departments = CompanyDBContext.Set <Department>().ToList(); for (int i = 0; i < departments.Count(); i++) { Department dep = departments[i]; dep.Workers = GetWorkers(dep.Id); if (dep.BossId.HasValue) { dep.Boss = GetWorker(dep.BossId.Value); } } return(departments); } }
public void UpdateDepartment(Department Entity) { using (var CompanyDBContext = new CompanyDBContext()) { var OldEntity = CompanyDBContext.Set <Department>().Find(Entity.Id); OldEntity.Name = Entity.Name; if (Entity.Boss != null) { OldEntity.BossId = Entity.Boss.Id; } else { OldEntity.BossId = null; } CompanyDBContext.SaveChanges(); } }
public void SetUp() { // Insert seed data into the database using one instance of the context using (var context = new CompanyDBContext(options)) { context.Database.EnsureDeleted(); context.Exchange.Add(new Exchange { Name = "New York Stock Exchange" }); context.Exchange.Add(new Exchange { Name = "Nasdaq" }); context.Exchange.Add(new Exchange { Name = "Japan Exchange Group" }); context.Exchange.Add(new Exchange { Name = "London Stock Exchange" }); context.Exchange.Add(new Exchange { Name = "Shanghai Stock Exchange" }); context.Exchange.Add(new Exchange { Name = "Hong Kong Stock Exchange" }); context.Exchange.Add(new Exchange { Name = "Euronext" }); context.Exchange.Add(new Exchange { Name = "Toronto Stock Exchange" }); context.SaveChanges(); } dao = new ExchangeDAO(new CompanyDBContext(options)); }
public void SetUp() { // Insert seed data into the database using one instance of the context using (var context = new CompanyDBContext(options)) { context.Database.EnsureDeleted(); context.Tickers.Add(new Ticker { CompanyId = 1, Name = "AAA" }); context.Tickers.Add(new Ticker { CompanyId = 1, Name = "GME" }); context.Tickers.Add(new Ticker { CompanyId = 2, Name = "GOOGL" }); context.Tickers.Add(new Ticker { CompanyId = 2, Name = "GOOG" }); context.Tickers.Add(new Ticker { CompanyId = 2, Name = "NFLX" }); context.Tickers.Add(new Ticker { CompanyId = 3, Name = "G" }); context.Tickers.Add(new Ticker { CompanyId = 3, Name = "D" }); context.Tickers.Add(new Ticker { CompanyId = 3, Name = "AAPL" }); context.SaveChanges(); } dao = new TickerDAO(new CompanyDBContext(options)); }
public void SetUp() { // Insert seed data into the database using one instance of the context using (var context = new CompanyDBContext(options)) { context.Database.EnsureDeleted(); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 1, ExchangeId = 1 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 1, ExchangeId = 2 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 2, ExchangeId = 3 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 2, ExchangeId = 4 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 2, ExchangeId = 5 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 3, ExchangeId = 2 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 3, ExchangeId = 3 }); context.CompanyExchange.Add(new Models.CompanyExchange { CompanyId = 3, ExchangeId = 4 }); context.SaveChanges(); } dao = new CompanyExchangeDAO(new CompanyDBContext(options)); }