Пример #1
0
 public void Insert(ApplicantBM model)
 {
     using (var context = new DataBaseContext())
     {
         context.Applicants.Add(CreateModel(model, new Applicant()));
         context.SaveChanges();
     }
 }
Пример #2
0
 private Applicant CreateModel(ApplicantBM model, Applicant applicant)
 {
     applicant.Name       = model.Name;
     applicant.Surname    = model.Surname;
     applicant.Patronymic = model.Patronymic;
     applicant.Birthday   = model.Birthday;
     applicant.Specialty  = model.Specialty;
     applicant.Education  = model.Education;
     return(applicant);
 }
Пример #3
0
 public void CreateOrUpdate(ApplicantBM model)
 {
     if (model.Id.HasValue)
     {
         _applicantStorage.Update(model);
     }
     else
     {
         _applicantStorage.Insert(model);
     }
 }
Пример #4
0
 public void Update(ApplicantBM model)
 {
     using (var context = new DataBaseContext())
     {
         Applicant element = context.Applicants.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Соискатель не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
Пример #5
0
 public List <ApplicantVM> GetFilteredList(ApplicantBM model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new DataBaseContext())
     {
         return(context.Applicants
                .Where(rec => rec.Birthday >= model.Birthday)
                .Select(CreateModel).ToList());
     }
 }
Пример #6
0
        public void Delete(ApplicantBM model)

        {
            var element = _applicantStorage.GetElement(new ApplicantBM
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Соискатель не найден");
            }
            _applicantStorage.Delete(model);
        }
Пример #7
0
 public List <ApplicantVM> Read(ApplicantBM model)
 {
     if (model == null)
     {
         return(_applicantStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <ApplicantVM> {
             _applicantStorage.GetElement(model)
         });
     }
     return(_applicantStorage.GetFilteredList(model));
 }
Пример #8
0
 public ApplicantVM GetElement(ApplicantBM model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new DataBaseContext())
     {
         var applicant = context.Applicants
                         .FirstOrDefault(rec => rec.Id == model.Id);
         return(applicant != null?
                CreateModel(applicant) : null);
     }
 }
Пример #9
0
 public void Delete(ApplicantBM model)
 {
     using (var context = new DataBaseContext())
     {
         Applicant element = context.Applicants.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Applicants.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Соискатель не найден");
         }
     }
 }