Ejemplo n.º 1
0
 public Car Get(Expression <Func <Car, bool> > filter)
 {
     using (CareContext context = new CareContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
        public List <Resident> FilterResidentsByCareLevel(string careLevel)
        {
            List <Resident> residents = new List <Resident>();

            using (var context = new CareContext()) {
                /*
                 * residents = context.Residents.Where(e => e.CareLevel.Equals(careLevel)).ToList();
                 *
                 * oder:
                 *
                 */

                IQueryable <Resident> residentsQueryList = from resident in context.Residents
                                                           where resident.CareLevel == careLevel
                                                           select resident;

                foreach (Resident res in residentsQueryList)
                {
                    residents.Add(res);
                }

                if (residents.Count > 0)
                {
                    return(residents);
                }
                else
                {
                    throw new ArgumentException("Keiner der Bewohner hat dieses Care Level.");
                }
            }
        }
Ejemplo n.º 3
0
        public Resident FindResidentById(int residentId)
        {
            using (var context = new CareContext()) {
                Resident resident = context.Residents.Find(residentId);

                return(resident);
            }
        }
Ejemplo n.º 4
0
 public void DeleteResidentWithVisitors(int residentId)
 {
     using (var context = new CareContext()) {
         Resident res = context.Residents.Find(residentId);
         context.Residents.Remove(res);
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public void Update(Car entity)
 {
     using (CareContext context = new CareContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void Add(Car entity)
 {
     using (CareContext context = new CareContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Ejemplo n.º 7
0
        public List <Visitor> GetVisitorListForResidentId(int residentId)
        {
            List <Visitor> visitorList = new List <Visitor>();

            using (var context = new CareContext()) {
                visitorList = context.Visitors.Where(e => e.ResidentId == residentId).ToList();
            }
            return(visitorList);
        }
Ejemplo n.º 8
0
 public void Delete(Car entity)
 {
     using (CareContext context = new CareContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
        public List <Resident> FilterResidentsByAge(int minAge, int maxAge)
        {
            List <Resident> residents = new List <Resident>();

            using (var context = new CareContext()) {
                residents = context.Residents.Where(a => a.Age >= minAge && a.Age <= maxAge).ToList();
            }

            return(residents);
        }
Ejemplo n.º 10
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (CareContext context = new CareContext())
     {
         if (filter == null)
         {
             return(context.Set <Car>().ToList());
         }
         else
         {
             return(context.Set <Car>().Where(filter).ToList());
         }
     }
 }
Ejemplo n.º 11
0
        public int CountNumberOfEquipmentCategories()
        {
            int numberOfCats = 0;

            using (var context = new CareContext()) {
                var residents = context.Rooms.ToList(); // zuerst die Liste holen

                var query = residents
                            .GroupBy(e => e.Equipment).Select(b => b).ToList(); // dann kann GroupBy darauf ausgeführt werden

                numberOfCats = query.Count;
            }
            return(numberOfCats);
        }
Ejemplo n.º 12
0
        public List <Resident> GetResidentListForCareTakerId(int careTakerId)
        {
            List <Resident> residents = new List <Resident>();

            using (var context = new CareContext()) {
                List <ResidentCareTaker> residentCareTakers = context.ResidentCareTakers
                                                              .Where(e => e.CareTakerId == careTakerId).ToList();

                foreach (ResidentCareTaker resCareTaker in residentCareTakers)
                {
                    Resident resident = context.Residents.Find(resCareTaker.ResidentId);
                    residents.Add(resident);
                }
                return(residents);
            }
        }
Ejemplo n.º 13
0
        public List <CareTaker> GetCaretTakerListForResidentId(int residentId)
        {
            List <CareTaker> careTakers = new List <CareTaker>();

            using (var context = new CareContext()) {
                List <ResidentCareTaker> residentCareTakers = context.ResidentCareTakers
                                                              .Where(e => e.ResidentId == residentId).ToList();

                foreach (ResidentCareTaker resCareTaker in residentCareTakers)
                {
                    CareTaker careTaker = context.CareTakers.Find(resCareTaker.CareTakerId);
                    careTakers.Add(careTaker);
                }
                return(careTakers);
            }
        }
        public int CountNumberOfEquipmentCategories()
        {
            int numberOfCats = 0;

            using (var context = new CareContext()) {
                var residents = context.Rooms.ToList(); // zuerst die Liste holen

                var query = residents
                            .GroupBy(e => e.Equipment).Select(b => b).ToList(); // dann kann GroupBy darauf ausgeführt werden

                numberOfCats = query.Count;

                /*var catGroups = from res in residents
                 *          group res by res.Equipment;
                 *
                 * foreach (var group in catGroups) {
                 *  numberOfCats++;
                 * }*/
            }
            return(numberOfCats);
        }
Ejemplo n.º 15
0
        public Resident UpdateNameResident(int residentId, string preName, string lastName)
        {
            Resident resident = new Resident();

            using (var context = new CareContext()) {
                try {
                    resident = context.Residents.Find(residentId);

                    if (!resident.Prename.Equals(preName) && !String.IsNullOrEmpty(preName))
                    {
                        resident.Prename = preName;
                    }
                    if (!resident.LastName.Equals(lastName) && !String.IsNullOrEmpty(lastName))
                    {
                        resident.LastName = lastName;
                    }

                    context.SaveChanges();
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
            }
            return(resident);
        }
        public List <Resident> FilterResidentByRoomEquipment(string equipment)
        {
            List <Resident> residents = new List <Resident>();

            using (var context = new CareContext()) {
                /*residents = context.Residents.Where(p => p.Room.Equipment.Equals(equipment)).ToList();
                 * if (residents.Count == 0) {
                 *  throw new ArgumentException($"Keiner dieser Bewohner hat die Ausstattungskategorie {equipment}");
                 * }
                 *
                 * oder
                 */

                IQueryable <Resident> residentList = from resident in context.Residents
                                                     where resident.Room.Equipment == equipment
                                                     select resident;

                foreach (Resident res in residentList)
                {
                    residents.Add(res);
                }
            }
            return(residents);
        }
Ejemplo n.º 17
0
 public CareController(CareContext context)
 {
     _context = context;
 }