/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public TestamentExtractionViewModel Update(TestamentExtractionViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._TestamentExtractionRepository.Update(entity); TestamentExtraction entityAr = entity.ChildTranslatedTestamentExtractions.Where(x => x.Language == Language.Arabic).FirstOrDefault(); entityAr.Description = model.DescriptionAr; entityAr.Name = model.NameAr; this._TestamentExtractionRepository.Update(entityAr); TestamentExtraction entityEn = entity.ChildTranslatedTestamentExtractions.Where(x => x.Language == Language.English).FirstOrDefault(); entityEn.Description = model.DescriptionEn; entityEn.Name = model.NameEn; this._TestamentExtractionRepository.Update(entityEn); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public void ThrowExceptionIfExist(TestamentExtraction model) { ConditionFilter <TestamentExtraction, long> condition = new ConditionFilter <TestamentExtraction, long> { Query = (entity => entity.Name == model.Name && entity.Id != model.Id) }; var existEntity = this._TestamentExtractionRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException(); } }
/// <summary> /// Add an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public TestamentExtractionViewModel Add(TestamentExtractionViewModel model) { try { var entity = model.ToEntity(); entity = this._TestamentExtractionRepository.Add(entity); var entityAr = new TestamentExtraction { //Id = entity.Id, Description = model.DescriptionAr, Name = model.NameAr, Language = Language.Arabic }; this.ThrowExceptionIfExist(entityAr); entity.ChildTranslatedTestamentExtractions.Add(entityAr); this._TestamentExtractionRepository.Add(entityAr); var entityEn = new TestamentExtraction { //Id = entity.Id, Description = model.DescriptionEn, Name = model.NameEn, Language = Language.English }; this.ThrowExceptionIfExist(entityEn); entity.ChildTranslatedTestamentExtractions.Add(entityEn); this._TestamentExtractionRepository.Add(entityEn); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); } catch (Exception ex) { throw; } }