public void Insert(ApplicantBM model) { using (var context = new DataBaseContext()) { context.Applicants.Add(CreateModel(model, new Applicant())); context.SaveChanges(); } }
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); }
public void CreateOrUpdate(ApplicantBM model) { if (model.Id.HasValue) { _applicantStorage.Update(model); } else { _applicantStorage.Insert(model); } }
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(); } }
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()); } }
public void Delete(ApplicantBM model) { var element = _applicantStorage.GetElement(new ApplicantBM { Id = model.Id }); if (element == null) { throw new Exception("Соискатель не найден"); } _applicantStorage.Delete(model); }
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)); }
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); } }
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("Соискатель не найден"); } } }