Example #1
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(StoreMeasurementUnitViewModel model)
        {
            var entity = model.ToEntity();

            this._StoreMeasurementUnitsRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
Example #2
0
        /// <summary>
        /// Throw an exception if name is exist.
        /// </summary>
        /// <param name="model">StoreMeasurementUnit view model</param>
        public void ThrowExceptionIfExist(StoreMeasurementUnitViewModel model)
        {
            ConditionFilter <StoreMeasurementUnit, long> condition = new ConditionFilter <StoreMeasurementUnit, long>
            {
                Query = (entity =>
                         entity.Name == model.Name &&
                         entity.Id != model.Id)
            };
            var existEntity = this._StoreMeasurementUnitsRepository.Get(condition).FirstOrDefault();

            if (existEntity != null)
            {
                throw new ItemAlreadyExistException();
            }
        }
Example #3
0
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public StoreMeasurementUnitViewModel Update(StoreMeasurementUnitViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._StoreMeasurementUnitsRepository.Update(entity);

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

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