Exemple #1
0
 public Department GetDepartment(int id)
 {
     using (DemoDbEntities db = new DemoDbEntities())
     {
         return(db.Departments.Find(id));
     }
 }
Exemple #2
0
 public void DeleteDepartment(int id)
 {
     using (DemoDbEntities db = new DemoDbEntities())
     {
         db.Departments.Remove(db.Departments.FirstOrDefault(z => z.Id == id));
         db.SaveChanges();
     }
 }
Exemple #3
0
        public List <ViewModalDepartment> GetDepartments()
        {
            List <ViewModalDepartment> vmDepartment = new List <ViewModalDepartment>()
            {
            };

            using (DemoDbEntities db = new DemoDbEntities())
            {
                var query = (from i in db.Departments select new { i.Id, i.Description, i.Address, i.Active, TotalUsers = (from io in db.Users where io.DepartmentId == i.Id select new { io.DepartmentId }).Count() }).ToList();
                foreach (var item in query)
                {
                    vmDepartment.Add(new ViewModalDepartment()
                    {
                        Id          = item.Id,
                        Description = item.Description,
                        Address     = item.Address,
                        Active      = item.Active,
                        TotalUsers  = item.TotalUsers,
                    });
                }

                return(vmDepartment);
            }
        }