public bool Update(CompCv entity) { if (entity == null) { throw new Exception("CompCv 無對應資料可更新"); } var compCvInDb = _dbContext.Country.First(c => c.CountryId == entity.CountryId); if (compCvInDb == null) { throw new Exception("CompCv 無對應資料可更新"); } _dbContext.CompCv.AddOrUpdate(entity); foreach (var certificateEntity in entity.CompCvCertificates) { _dbContext.CompCvCertificate.AddOrUpdate(certificateEntity); } foreach (var educationEntity in entity.CompCvEducations) { _dbContext.CompCvEducation.AddOrUpdate(educationEntity); } foreach (var langReqEntity in entity.CompCvLanguageRequirements) { _dbContext.CompCvLanguageRequirement.AddOrUpdate(langReqEntity); } return(_dbContext.SaveChanges() > 0); }
private CompCvVM ToCompCvVM(CompCv entity) { var result = new CompCvVM(); result.CvId = entity.CvId; result.FirstName = entity.FirstName; result.LastName = entity.LastName; result.CountryId = entity.CountryId; result.CountyId = entity.CountyId; result.Certificates = entity.CompCvCertificates .Select(cert => ToCerttificateVM(cert)) .ToList(); result.Educations = entity.CompCvEducations .Select(edu => ToEducationVM(edu)) .ToList(); result.LanguageRequirements = entity.CompCvLanguageRequirements .Select(lang => ToLanguageRequirementVM(lang)) .ToList(); return(result); }
private CompCv ToCompCv(CompCvVM vm, bool isUpdate = false) { var cv = new CompCv(); cv.CvId = isUpdate ? vm.CvId : Guid.NewGuid(); cv.FirstName = vm.FirstName; cv.LastName = vm.LastName; cv.CountryId = vm.CountryId; cv.CountyId = vm.CountyId; cv.CompCvCertificates = vm.Certificates .Where(c => string.IsNullOrWhiteSpace(c.CertificateName) == false) .Select(c => { var entity = ToCompCvCerttificate(c); entity.CertificateId = c.CertificateId ?? Guid.NewGuid(); entity.CvId = cv.CvId; return(entity); }).ToList(); cv.CompCvEducations = vm.Educations .Where(c => string.IsNullOrWhiteSpace(c.AcademyName) == false) .Select(c => { var entity = ToCompCvEducations(c); entity.EducationId = c.EducationId ?? Guid.NewGuid(); entity.CvId = cv.CvId; return(entity); }).ToList(); cv.CompCvLanguageRequirements = vm.LanguageRequirements .Select(c => { var entity = ToCompCvLanguageRequirement(c); entity.LanguageRequirementId = c.LanguageRequirementId ?? Guid.NewGuid(); entity.CvId = cv.CvId; return(entity); }).ToList(); return(cv); }
public bool Update(CompCv entity) { if (entity == null) { throw new Exception("CompCv 無對應資料可更新"); } var compCvInDb = _dbContext.Country.First(c => c.CountryId == entity.CountryId); if (compCvInDb == null) { throw new Exception("CompCv 無對應資料可更新"); } _dbContext.CompCv.Update(entity); _dbContext.CompCvCertificate.AttachRange(entity.CompCvCertificates); _dbContext.CompCvEducation.AttachRange(entity.CompCvEducations); _dbContext.CompCvLanguageRequirement.AttachRange(entity.CompCvLanguageRequirements); return(_dbContext.SaveChanges() > 0); }
public void Add(CompCv entity) { _dbContext.CompCv.Add(entity); _dbContext.SaveChanges(); }