Beispiel #1
0
        protected override async Task <bool> Validate(Order entityObject)
        {
            StringBuilder sb    = new StringBuilder();
            bool          valid = await base.Validate(entityObject);

            if (entityObject.OrderAmount <= 0)
            {
                valid = false;
                sb.Append(Environment.NewLine + "Total Amount cannot be negative");
            }
            if (entityObject.TotalQuantity <= 0)
            {
                valid = false;
                sb.Append(Environment.NewLine + "Total Quantity cannot be negative");
            }
            CustomerBL iCustomerBL    = new CustomerBL();
            var        existingObject = await iCustomerBL.GetCustomerByCustomerIDBL(entityObject.CustomerID);

            if (existingObject == null)
            {
                valid = false;
                sb.Append(Environment.NewLine + $"CustomerID {entityObject.CustomerID} does not exists");
            }
            if (valid == false)
            {
                throw new Exception(sb.ToString());
            }
            return(valid);
        }
Beispiel #2
0
        public async Task <CustomerReport> GetCustomerReportByRetailIDBL(Guid CustomerID)
        {
            CustomerReport customerReport = new CustomerReport
            {
                CustomerID = CustomerID
            };
            CustomerBL customerBL = new CustomerBL();
            Customer   customer   = await customerBL.GetCustomerByCustomerIDBL(customerReport.CustomerID);

            customerReport.CustomerName = customer.CustomerName;
            OrderBL      order     = new OrderBL();
            List <Order> orderList = await order.GetOrdersByCustomerIDBL(CustomerID);

            foreach (Order item in orderList)
            {
                customerReport.CustomerSalesCount++;
                customerReport.CustomerSalesAmount += item.OrderAmount;
            }
            return(customerReport);
        }