public void CreateOrUpdate(CertificateAddModel addModel) { var resume = _managerRepository.Get(addModel.ResumeManagerId.Value).Resume; foreach (var certificate in addModel.Certificates) { certificate.ResumeId = resume.Id; if (!this.UpdateCertificate(certificate)) { this.CreateCertificate(certificate); } } }
public CertificateAddModel Get(int managerId) { var resume = _managerRepository.Get(managerId).Resume; if (resume == null || resume.CertificatesAndTrainings.Count == 0) { return(null); } CertificateAddModel addModel = new CertificateAddModel(); addModel.ResumeManagerId = managerId; foreach (var certificate in resume.CertificatesAndTrainings) { addModel.Certificates.Add(certificate.ToModel()); } return(addModel); }
public ActionResult Certificates(int managerId, CertificateAddModel addModel) { if (!ModelState.IsValid) { return(View(addModel)); } int userId = User.Identity.GetUserId <int>(); // проверяем, владелец ли резюме шлет запрос на его изменение if (!_managerService.IsOwnedBy(userId, managerId)) { return(new HttpUnauthorizedResult()); } addModel.ResumeManagerId = managerId; _certificateService.CreateOrUpdate(addModel); return(RedirectToAction(string.Format("Certificates/{0}", managerId))); }