Exemplo n.º 1
0
 public void Delete(DiseaseBindingModel model)
 {
     using (var context = new ClinicDataBase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 Disease element = context.Diseases.FirstOrDefault(rec => rec.Id == model.Id);
                 if (element != null)
                 {
                     context.Diseases.Remove(element);
                     context.SaveChanges();
                 }
                 else
                 {
                     throw new Exception("Элемент не найден");
                 }
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Exemplo n.º 2
0
 private Disease CreateModel(DiseaseBindingModel model, Disease disease)
 {
     disease.DiseaseName = model.DiseaseName;
     disease.Difficulty  = model.Difficulty;
     disease.Class       = model.Class;
     disease.DoctorId    = (int)model.DoctorId;
     return(disease);
 }
Exemplo n.º 3
0
        public void Delete(DiseaseBindingModel model)
        {
            var element = _diseaseStorage.GetElement(new DiseaseBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Косметика не найдена");
            }
            _diseaseStorage.Delete(model);
        }
Exemplo n.º 4
0
 public List <DiseaseViewModel> Read(DiseaseBindingModel model)
 {
     if (model == null)
     {
         return(_diseaseStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <DiseaseViewModel> {
             _diseaseStorage.GetElement(model)
         });
     }
     return(_diseaseStorage.GetFilteredList(model));
 }
Exemplo n.º 5
0
        public void CreateOrUpdate(DiseaseBindingModel model)
        {
            var element = _diseaseStorage.GetElement(new DiseaseBindingModel {
                DiseaseName = model.DiseaseName
            });

            if (element != null && element.Id != model.Id)
            {
                throw new Exception("Уже есть болезнь с таким названием");
            }
            if (model.Id.HasValue)
            {
                _diseaseStorage.Update(model);
            }
            else
            {
                _diseaseStorage.Insert(model);
            }
        }
Exemplo n.º 6
0
 public void Insert(DiseaseBindingModel model)
 {
     using (var context = new ClinicDataBase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 context.Diseases.Add(CreateModel(model, new Disease()));
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Exemplo n.º 7
0
 public List <DiseaseViewModel> GetFilteredList(DiseaseBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new ClinicDataBase())
     {
         return(context.Diseases
                .Include(rec => rec.Doctor)
                .Where(rec => rec.DoctorId == model.DoctorId || rec.DiseaseName.Contains(model.DiseaseName))
                .ToList()
                .Select(rec => new DiseaseViewModel
         {
             Id = rec.Id,
             DiseaseName = rec.DiseaseName,
             Class = rec.Class,
             Difficulty = rec.Difficulty,
             DoctorId = rec.DoctorId
         })
                .ToList());
     }
 }
Exemplo n.º 8
0
 public DiseaseViewModel GetElement(DiseaseBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new ClinicDataBase())
     {
         var tmp     = model.DoctorId;
         var disease = context.Diseases
                       .Include(rec => rec.Doctor)
                       .FirstOrDefault(rec => rec.DiseaseName == model.DiseaseName || rec.Id == model.Id);
         return(disease != null ?
                new DiseaseViewModel
         {
             Id = disease.Id,
             DiseaseName = disease.DiseaseName,
             Difficulty = disease.Difficulty,
             Class = disease.Class,
             DoctorId = disease.DoctorId
         } :
                null);
     }
 }