Ejemplo n.º 1
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(InventoryOpeningBalanceViewModel model)
        {
            var entity = model.ToEntity();

            this._InventoryOpeningBalancesRepository.Delete(entity);

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

            //if (existEntity != null)
            //    throw new ItemAlreadyExistException();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public InventoryOpeningBalanceViewModel Update(InventoryOpeningBalanceViewModel model)
        {
            this.ThrowExceptionIfExist(model);
            this._closedMonthsService.ValidateIfMonthIsClosed(model.Date.Value);

            var entity = this._InventoryOpeningBalancesRepository.Get(model.Id);

            entity.Code        = model.Code;
            entity.Description = model.Description;
            entity.InventoryId = model.InventoryId;

            //var entity = model.ToEntity();


            entity = this._InventoryOpeningBalancesRepository.Update(entity);

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

            model = entity.ToModel();
            return(model);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public InventoryOpeningBalanceViewModel Add(InventoryOpeningBalanceViewModel model)
        {
            this.ThrowExceptionIfExist(model);
            this._closedMonthsService.ValidateIfMonthIsClosed(model.Date.Value);

            var      entity = model.ToEntity();
            DateTime now    = DateTime.Now;

            if (model.InventoryOpeningBalanceCostCenter != null)
            {
                foreach (var item in entity.InventoryOpeningBalanceCostCenter)
                {
                    item.CreationDate            = now;
                    item.InventoryOpeningBalance = entity;
                }
            }

            if (model.Products != null)
            {
                foreach (var item in entity.Products)
                {
                    item.CreationDate            = now;
                    item.InventoryOpeningBalance = entity;
                }
            }

            entity = this._InventoryOpeningBalancesRepository.Add(entity);

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

            //  this._journalPostingsService.TryPostAutomatic(entity.Id, MovementType.InventoryOpeningBalance);

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