Ejemplo n.º 1
0
        private async Task <bool> ValidateItem(CustomerSalesOrder CustomerSalesOrder)
        {
            if (CustomerSalesOrder.CustomerSalesOrderPromotions != null)
            {
                var Ids        = CustomerSalesOrder.CustomerSalesOrderPromotions.Select(x => x.ItemId).ToList();
                var ItemFilter = new ItemFilter
                {
                    Skip = 0,
                    Take = int.MaxValue,
                    Id   = new IdFilter {
                        In = Ids
                    },
                    StatusId = new IdFilter {
                        Equal = Enums.StatusEnum.ACTIVE.Id
                    },
                    Selects = ItemSelect.Id
                };

                var listIdsInDB       = (await UOW.ItemRepository.List(ItemFilter)).Select(x => x.Id);
                var listIdsNotExisted = Ids.Except(listIdsInDB);
                foreach (var CustomerSalesOrderPromotion in CustomerSalesOrder.CustomerSalesOrderPromotions)
                {
                    if (listIdsNotExisted.Contains(CustomerSalesOrderPromotion.ItemId))
                    {
                        CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderValidator), nameof(CustomerSalesOrderPromotion.Item), ErrorCode.ItemNotExisted);
                    }
                }
            }
            return(CustomerSalesOrder.IsValidated);
        }
        public async Task <bool> ValidateId(CustomerSalesOrderPromotion CustomerSalesOrderPromotion)
        {
            CustomerSalesOrderPromotionFilter CustomerSalesOrderPromotionFilter = new CustomerSalesOrderPromotionFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerSalesOrderPromotion.Id
                },
                Selects = CustomerSalesOrderPromotionSelect.Id
            };

            int count = await UOW.CustomerSalesOrderPromotionRepository.Count(CustomerSalesOrderPromotionFilter);

            if (count == 0)
            {
                CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderPromotionValidator), nameof(CustomerSalesOrderPromotion.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Ejemplo n.º 3
0
        private async Task <bool> ValidatePromotion(CustomerSalesOrder CustomerSalesOrder)
        {
            if (CustomerSalesOrder.CustomerSalesOrderPromotions != null)
            {
                await ValidateItem(CustomerSalesOrder);

                //validate đơn vị tính sản phẩm khuyến mãi
                var Ids = CustomerSalesOrder.CustomerSalesOrderPromotions.Select(x => x.UnitOfMeasureId).ToList();
                var UnitOfMeasureFilter = new UnitOfMeasureFilter
                {
                    Skip = 0,
                    Take = int.MaxValue,
                    Id   = new IdFilter {
                        In = Ids
                    },
                    StatusId = new IdFilter {
                        Equal = Enums.StatusEnum.ACTIVE.Id
                    },
                    Selects = UnitOfMeasureSelect.Id
                };

                var listIdsInDB       = (await UOW.UnitOfMeasureRepository.List(UnitOfMeasureFilter)).Select(x => x.Id);
                var listIdsNotExisted = Ids.Except(listIdsInDB);

                foreach (var CustomerSalesOrderPromotion in CustomerSalesOrder.CustomerSalesOrderPromotions)
                {
                    if (listIdsNotExisted.Contains(CustomerSalesOrderPromotion.UnitOfMeasureId))
                    {
                        CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderValidator), nameof(CustomerSalesOrderPromotion.UnitOfMeasure), ErrorCode.UnitOfMeasureEmpty);
                    }
                    //validate số lượng
                    if (CustomerSalesOrderPromotion.Quantity <= 0)
                    {
                        CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderValidator), nameof(CustomerSalesOrderPromotion.Quantity), ErrorCode.QuantityEmpty);
                    }
                }
            }
            return(CustomerSalesOrder.IsValidated);
        }