Beispiel #1
0
        public bool FillEntity(ref object Entity)
        {
            if (Entity == null)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(this.DataFiled))
            {
                return(true);
            }
            if (this.Value == null || string.IsNullOrEmpty(this.Value.ToString()))
            {
                return(true);
            }

            PropertyInfo propertyInfo = Entity.GetType().GetProperty(this.DataFiled);

            if (propertyInfo == null)
            {
                return(true);
            }
            object filedValue = this.Value;

            if (BaseEntityHelper.GetValue(ref filedValue, propertyInfo, this.DataControlName))
            {
                propertyInfo.SetValue(Entity, filedValue, null);
            }
            return(true);
        }
Beispiel #2
0
        private List <PurchaseUnit> CreatePurchaseUnits(List <PurchaseUnitViewModel> purchaseUnitsVM, Purchase purchase)
        {
            var purchaseUnits = new List <PurchaseUnit>(purchaseUnitsVM.Count);

            _purchaseUnitsService.DeletePurchaseUnitsByPurchaseId(purchase.Id);

            foreach (var purchaseUnit in purchaseUnitsVM)
            {
                var product = _productsService.GetEntityById(purchaseUnit.Product.Id);

                if (product != null)
                {
                    purchaseUnits.Add(new PurchaseUnit
                    {
                        Product     = product,
                        Count       = purchaseUnit.Count,
                        CreatedDate = DateTime.Now,
                        StorePrice  = purchaseUnit.StorePrice,
                        Status      = PurchaseUnitStatuses.New,
                        Purchase    = purchase
                    });
                }
                else
                {
                    throw new EntityNotFoundException(BaseEntityHelper.Description(typeof(PurchaseUnit)), purchaseUnit.Id.Value);
                }
            }

            return(purchaseUnits);
        }
Beispiel #3
0
        public Purchase GetPurchaseEagerById(Guid id)
        {
            if (!_service.EntityExist(id))
            {
                throw new EntityNotFoundException(BaseEntityHelper.Description(typeof(Purchase)), id);
            }

            return(_purchasesService.GetPurchaseEagerById(id));
        }
Beispiel #4
0
        public void Update(PurchaseViewModel purchaseViewModel)
        {
            var purchase = _service.GetEntityById(purchaseViewModel.Id);

            if (purchase == null)
            {
                throw new EntityNotFoundException(BaseEntityHelper.Description(typeof(Purchase)), purchaseViewModel.Id.Value);
            }

            purchase.Date = purchaseViewModel.Date;

            purchase.PurchaseUnits     = CreatePurchaseUnits(purchaseViewModel.PurchaseUnits, purchase);
            purchase.DeliveryPurchases = CreateDeliveryPurchases(purchaseViewModel.Deliveries, purchase);

            _service.UpdateEntity(purchase);
        }