/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(ExpensesTypeViewModel model) { var entity = model.ToEntity(); this._ExpensesTypesRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">ExpensesType view model</param> public void ThrowExceptionIfExist(ExpensesTypeViewModel model) { ConditionFilter <ExpensesType, long> condition = new ConditionFilter <ExpensesType, long> { Query = (entity => entity.Code == model.Code && entity.Id != model.Id) }; var existEntity = this._ExpensesTypesRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException((int)ErrorCodeEnum.CodeAlreadyExist); } }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public ExpensesTypeViewModel Update(ExpensesTypeViewModel model) { this.ThrowExceptionIfExist(model); // var entity = model.ToEntity(); var entity = this._ExpensesTypesRepository.Get(model.Id); entity.Code = model.Code; entity = this._ExpensesTypesRepository.Update(entity); ConditionFilter <ExpensesType, long> conditionFilter = new ConditionFilter <ExpensesType, long>() { Query = (x => x.ParentKeyExpensesTypeId == entity.Id) }; var childs = this._ExpensesTypesRepository.Get(conditionFilter); if (childs.Count() > 0) { var ar = childs.FirstOrDefault(x => x.Language == Language.Arabic); ar.Name = model.NameAr; ar.Description = model.DescriptionAr; this._ExpensesTypesRepository.Update(ar); var en = childs.FirstOrDefault(x => x.Language == Language.English); en.Name = model.NameEn; en.Description = model.DescriptionEn; this._ExpensesTypesRepository.Update(en); } #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
/// <summary> /// Add an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public ExpensesTypeViewModel Add(ExpensesTypeViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._ExpensesTypesRepository.Add(entity); var entityAr = new ExpensesType { Id = entity.Id, Name = model.NameAr, Description = model.DescriptionAr, Language = Framework.Common.Enums.Language.Arabic }; entity.ChildTranslatedExpensesTypes.Add(entityAr); this._ExpensesTypesRepository.Add(entityAr); var entityEn = new ExpensesType { Id = entity.Id, Name = model.NameEn, Description = model.DescriptionEn, Language = Framework.Common.Enums.Language.English }; entity.ChildTranslatedExpensesTypes.Add(entityEn); this._ExpensesTypesRepository.Add(entityEn); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }