Exemple #1
0
        /// <summary>
        /// Validations on data before adding or updating.
        /// </summary>
        /// <param name="entityObject">Represents object to be validated.</param>
        /// <returns>Returns a boolean value, that indicates whether the data is valid or not.</returns>
        protected async override Task <bool> Validate(OnlineReturn entityObject)
        {
            //Create string builder
            StringBuilder sb    = new StringBuilder();
            bool          valid = await base.Validate(entityObject);

            //OrderID is Unique
            OrderBL iorderBL = new OrderBL();

            var existingObject = await iorderBL.GetOrderByOrderIDBL(entityObject.OrderID);

            if (existingObject == null)
            {
                valid = false;
                sb.Append(Environment.NewLine + $"OrderID {entityObject.OrderID} does not exists");
            }



            ////productID is unique
            //ProductBL iproductBL = new ProductBL();

            //var existingObject2 = await iproductBL.GetProductByProductIDBL(entityObject.ProductID);
            //if (existingObject2 == null)
            //{
            //    valid = false;
            //    sb.Append(Environment.NewLine + $"ProductID {entityObject.ProductID} already exists");
            //}

            if (valid == false)
            {
                throw new System.Exception(sb.ToString());
            }
            return(valid);
        }
Exemple #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);
        }