예제 #1
0
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public AdvancesTypeViewModel Update(AdvancesTypeViewModel model)
        {
            //this.ThrowExceptionIfExist(model);

            var entity = this._AdvancesTypesRepository.Get(model.Id.Value);

            entity = this._AdvancesTypesRepository.Update(entity);

            var entityAr = entity.ChildTranslatedAdvancesTypes.FirstOrDefault(x => x.Language == Language.Arabic);

            entityAr.Name = model.NameAr;

            this._AdvancesTypesRepository.Update(entityAr);

            var entityEn = entity.ChildTranslatedAdvancesTypes.FirstOrDefault(x => x.Language == Language.English);

            entityEn.Name = model.NameEn;

            this._AdvancesTypesRepository.Update(entityEn);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }
예제 #2
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(AdvancesTypeViewModel model)
        {
            var entity = model.ToEntity();

            this._AdvancesTypesRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
예제 #3
0
        /// <summary>
        /// Throw an exception if name is exist.
        /// </summary>
        /// <param name="model">AdvancesType view model</param>
        public void ThrowExceptionIfExist(AdvancesTypeViewModel model)
        {
            ConditionFilter <AdvancesType, int> condition = new ConditionFilter <AdvancesType, int>
            {
                Query = (entity =>
                         entity.ParentKeyAdvancesTypeId != null &&
                         entity.ParentKeyAdvancesTypeId != model.Id &&
                         entity.Id != model.Id)
            };
            var existEntity = this._AdvancesTypesRepository.Get(condition).FirstOrDefault();

            if (existEntity != null)
            {
                throw new ItemAlreadyExistException();
            }
        }
예제 #4
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public AdvancesTypeViewModel Add(AdvancesTypeViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._AdvancesTypesRepository.Add(entity);

            var entityAr = new AdvancesType
            {
                Name     = model.NameAr,
                Language = Framework.Common.Enums.Language.Arabic,
                ParentKeyAdvancesTypes = entity
            };

            entity.ChildTranslatedAdvancesTypes.Add(entityAr);
            this._AdvancesTypesRepository.Add(entityAr);

            var entityEn = new AdvancesType
            {
                Name     = model.NameEn,
                Language = Framework.Common.Enums.Language.English,
                ParentKeyAdvancesTypes = entity
            };

            entity.ChildTranslatedAdvancesTypes.Add(entityEn);
            this._AdvancesTypesRepository.Add(entityEn);


            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }