コード例 #1
0
#pragma warning disable CS0114 // Member hides inherited member; missing override keyword
        protected async Task <bool> Validate(Order entityObject)
#pragma warning restore CS0114 // Member hides inherited member; missing override keyword
        {
            //Create string builder
            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");
            }
            //CustomerID is Unique
            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 System.Exception(sb.ToString());
            }
            return(valid);
        }
コード例 #2
0
        public async Task <CustomerReport> GetCustomerReportByRetailIDBL(Guid CustomerID)
        {
            CustomerReport CustomerReport = new CustomerReport();

            CustomerReport.CustomerID = CustomerID;
            Customer   Customer   = new Customer();
            CustomerBL CustomerBL = new CustomerBL();

            Customer = await CustomerBL.GetCustomerByCustomerIDBL(CustomerReport.CustomerID);

            CustomerReport.CustomerName = Customer.CustomerName;
            List <Order> orderList = new List <Order>();
            OrderBL      order     = new OrderBL();

            orderList = await order.GetOrdersByCustomerIDBL(CustomerID);

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

            return(CustomerReport);
        }