Esempio n. 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 GreatOutdoorException(sb.ToString());
            }
            return(valid);
        }
        public async Task <RetailerReport> GetRetailerReportByRetailIDBL(Guid RetailerID)
        {
            RetailerReport retailerReport = new RetailerReport();

            retailerReport.RetailerID = RetailerID;
            Retailer   retailer   = new Retailer();
            RetailerBL retailerBL = new RetailerBL();

            retailer = await retailerBL.GetRetailerByRetailerIDBL(retailerReport.RetailerID);

            retailerReport.RetailerName = retailer.RetailerName;
            List <Order> orderList = new List <Order>();
            OrderBL      order     = new OrderBL();

            orderList = await order.GetOrdersByRetailerIDBL(RetailerID);

            foreach (Order item in orderList)
            {
                retailerReport.RetailerSalesCount++;
                retailerReport.RetailerSalesAmount += item.OrderAmount;
            }

            return(retailerReport);
        }