Пример #1
0
 public ChildBirth GetChildBirth(int childBirthId)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.ChildBirth.FirstOrDefault(x => x.Id == childBirthId);
     }
 }
Пример #2
0
 public IList<Females> GetFemales()
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Females.ToList();
     }
 }
 public MedicalServices GetMedicalService(int serviceId)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.MedicalServices.FirstOrDefault(x => x.Id == serviceId);
     }
 }
 public IList<MedicalServices> GetMedicalServices()
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.MedicalServices.ToList();
     }
 }
Пример #5
0
 public IList<ChildBirth> GetChildBirth()
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.ChildBirth.ToList();
     }
 }
Пример #6
0
 public Cages GetCage(int cageId)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Cages.FirstOrDefault(x => x.Id == cageId);
     }
 }
Пример #7
0
 public Males GetMale(int maleId)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Males.FirstOrDefault(x => x.Id == maleId);
     }
 }
Пример #8
0
 public Males GetMale(string maleName)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Males.FirstOrDefault(x => x.Name == maleName);
     }
 }
Пример #9
0
 public Parrents GetParrents(int femaleId)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Parrents.FirstOrDefault(x => x.FemaleId == femaleId);
     }
 }
Пример #10
0
 public IList<Cages> GetCages()
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Cages.ToList();
     }
 }
Пример #11
0
 public IList<Females> GetFemales(int cageId)
 {
     using (var context = new RabbitsDBEntities())
     {
         return context.Females.Where(x => x.CageId == cageId).ToList();
     }
 }
Пример #12
0
 public void AddParrents(Parrents parrents)
 {
     using (var context = new RabbitsDBEntities())
     {
         context.Parrents.Add(parrents);
         context.SaveChanges();
     }
 }
Пример #13
0
 public void AddChildBirth(ChildBirth childBirth)
 {
     using (var context = new RabbitsDBEntities())
     {
         context.ChildBirth.Add(childBirth);
         context.SaveChanges();
     }
 }
        public void AddMedicalService(MedicalServices medicalService)
        {
            using (var context = new RabbitsDBEntities())
            {
                if(IsNameExist(medicalService.MedicalServiceName, context))
                    throw new InvalidOperationException(AlreadyExist);

                context.MedicalServices.Add(medicalService);
                context.SaveChanges();
            }
        }
Пример #15
0
        public void AddCage(Cages cage)
        {
            using (var context = new RabbitsDBEntities())
            {
                if (IsNameExist(cage.Name, context))
                    throw new InvalidOperationException(AlreadyExist);

                context.Cages.Add(cage);
                context.SaveChanges();
            }
        }
Пример #16
0
        public void AddMale(Males male)
        {
            using (var context = new RabbitsDBEntities())
            {
                if (IsNameExist(male.Name, context))
                    throw new InvalidOperationException(AlreadyExist);

                context.Males.Add(male);
                context.SaveChanges();
            }
        }
Пример #17
0
        public void DeleteMale(int maleId)
        {
            using (var context = new RabbitsDBEntities())
            {
                var result = context.Males.FirstOrDefault(x => x.Id == maleId);
                if (result == null)
                    throw new InvalidOperationException(NotFound);

                context.Males.Remove(result);
                context.SaveChanges();
            }
        }
Пример #18
0
        public void DeleteParrents(int parrentsId)
        {
            using (var context = new RabbitsDBEntities())
            {
                var entity = context.Parrents.FirstOrDefault(x => x.Id == parrentsId);

                if (entity == null)
                    throw new InvalidOperationException(NotFound);

                context.Parrents.Remove(entity);
                context.SaveChanges();
            }
        }
Пример #19
0
        public void DeleteCage(int cageId)
        {
            using (var context = new RabbitsDBEntities())
            {
                var entity = context.Cages.FirstOrDefault(x => x.Id == cageId);

                if (entity == null)
                    throw new InvalidOperationException(DoesNotExist);

                context.Cages.Remove(entity);
                context.SaveChanges();
            }
        }
Пример #20
0
        public void DeleteFemaleFromCage(int femaleId)
        {
            using (var context = new RabbitsDBEntities())
            {
                var female = context.Females.FirstOrDefault(x => x.Id == femaleId);

                if (female == null)
                    throw new InvalidOperationException(DoesNotExist);

                female.CageId = null;

                context.SaveChanges();
            }
        }
Пример #21
0
        public void UpdateMale(Males male)
        {
            using (var context = new RabbitsDBEntities())
            {
                if (IsNameExist(male.Name, context))
                    throw new InvalidOperationException(AlreadyExist);

                var result = context.Males.FirstOrDefault(x => x.Id == male.Id);
                if (result == null)
                    throw new InvalidOperationException(NotFound);

                result.Name = male.Name;

                context.SaveChanges();
            }
        }
Пример #22
0
        public void UpdateParrents(Parrents parrents)
        {
            using (var context = new RabbitsDBEntities())
            {
                var entity = context.Parrents.FirstOrDefault(x => x.Id == parrents.Id);

                if(entity == null)
                    throw new InvalidOperationException(NotFound);

                entity.FatherId1 = parrents.FatherId1;
                entity.FatherId2 = parrents.FatherId2;
                entity.MotherId = parrents.MotherId;

                context.SaveChanges();
            }
        }
Пример #23
0
        public void UpdateCage(Cages cage)
        {
            using (var context = new RabbitsDBEntities())
            {
                if (IsNameExist(cage.Name, context))
                    throw new InvalidOperationException(AlreadyExist);

                var entity = context.Cages.FirstOrDefault(x => x.Id == cage.Id);

                if (entity == null)
                    throw new InvalidOperationException(DoesNotExist);

                entity.Name = cage.Name;

                context.SaveChanges();
            }
        }
Пример #24
0
        public void UpdateFemale(Females female)
        {
            using (var context = new RabbitsDBEntities())
            {
                var result = context.Females.FirstOrDefault(x => x.Id == female.Id);
                if (result == null)
                    throw new InvalidOperationException(DoesNotExist);

                if (result.Name != female.Name && IsNameExist(female.Name, context))
                    throw new InvalidOperationException(AlreadyExist);

                result.Name = female.Name;
                result.DateOfBirth = female.DateOfBirth;
                result.CageId = female.CageId;

                context.SaveChanges();
            }

        }
Пример #25
0
        public void UpdateChildBirth(ChildBirth childBirth)
        {
            using (var context = new RabbitsDBEntities())
            {
                var result = context.ChildBirth.FirstOrDefault(x => x.Id == childBirth.Id);
                if (result == null)
                    throw new InvalidOperationException(NotFound);

                result.FemaleId = childBirth.FemaleId;
                result.Birthday = childBirth.Birthday;
                result.ExpectBirthday = childBirth.ExpectBirthday;
                result.Notes = childBirth.Notes;
                result.MaleId1 = childBirth.MaleId1;
                result.MaleId2 = childBirth.MaleId2;
                result.StartDate1 = childBirth.StartDate1;
                result.StartDate2 = childBirth.StartDate2;
                result.ResultId = childBirth.ResultId;

                context.SaveChanges();
            }
        }
Пример #26
0
        public IList<ChildBirth> GetChildBirth(Filters filter)
        {
            using (var context = new RabbitsDBEntities())
            {
                IQueryable<ChildBirth> query = context.ChildBirth;

                if (!string.IsNullOrEmpty(filter.MaleName))
                    query = query.Where(x => x.MaleId1 == new MalesRepository().GetMale(filter.MaleName).Id);

                if (!string.IsNullOrEmpty(filter.FemaleName))
                    query = query.Where(x => x.FemaleId == new FemalesRepository().GetFemale(filter.FemaleName).Id);

                if (filter.DateFrom.HasValue)
                    query = query.Where(x => x.Birthday >= filter.DateFrom);

                if (filter.DateTo.HasValue)
                    query = query.Where(x => x.Birthday <= filter.DateTo);

                return query.ToList();
            }
        }
Пример #27
0
 static bool IsNameExist(string cageName, RabbitsDBEntities context)
 {
     return context.Cages.Count(x => x.Name == cageName) > 0;
 }
 static bool IsNameExist(string serviceName, RabbitsDBEntities context)
 {
     return context.MedicalServices.Count(x => x.MedicalServiceName == serviceName) > 0;
 }
Пример #29
0
 static bool IsNameExist(string maleName, RabbitsDBEntities context)
 {
     return context.Males.Count(x => x.Name == maleName) > 0;
 }