示例#1
0
        public SalesResponse GetSales()
        {
            SalesValidation salesValidation = new SalesValidation(new RepositoryFactory <SalesEntity>(), _appSettings.Value.MongoConnectionString);

            try
            {
                var salesValidationStatus = salesValidation.GetAllSales();
                if (salesValidationStatus.GotAllSales)
                {
                    return(new SalesResponse()
                    {
                        Message = "Sales found",
                        SalesEntity = salesValidationStatus.SalesEntity
                    });
                }
                else
                {
                    return(new SalesResponse()
                    {
                        Message = "Sales not found",
                        SalesEntity = null
                    });
                }
            }
            catch (KeyNotFoundException keyNotFound)
            {
                return(new SalesResponse()
                {
                    Message = keyNotFound.Message,
                    SalesEntity = null
                });
            }
        }
示例#2
0
        public OrderValidationStatus ValidateOrder(string accName, string custName, List <ProductEntity> products)
        {
            logger.Message = "Starting Validation On Order";
            dispatcher.interceptors.ForEach(f => f.Intercept(logger));

            var orderValidationStatus = new OrderValidationStatus()
            {
                IsValid = false
            };

            if (accName.Equals(null) || custName.Equals(null) || products.Equals(null))
            {
                return(orderValidationStatus);
            }

            var accountName  = accName.Trim();
            var customerName = custName.Trim();

            logger.Message = "Validate Account";
            dispatcher.interceptors.ForEach(f => f.Intercept(logger));
            invoker.Message = "ValidateAccountEntity()";
            dispatcher.interceptorsInv.ForEach(f => f.Intercept(invoker));
            var account = ValidateAccountEntity(accountName);

            if (account == null)
            {
                return(orderValidationStatus);
            }

            logger.Message = "Validate Customer";
            dispatcher.interceptors.ForEach(f => f.Intercept(logger));

            var customer = ValidateCustomerEntity(customerName);

            if (customer == null)
            {
                return(orderValidationStatus);
            }

            logger.Message = "Validate Products";
            dispatcher.interceptors.ForEach(f => f.Intercept(logger));

            if (ValidateProducts(products))
            {
                PriceCalculation pricing = new PriceCalculation(products, customer);
                logger.Message = "Calculating Total Price For Products";
                dispatcher.interceptors.ForEach(f => f.Intercept(logger));
                var totalCost = pricing.CalculateTotalCostOfProducts();
                logger.Message = ("Calculating Discounts");
                dispatcher.interceptors.ForEach(f => f.Intercept(logger));
                totalCost = pricing.CalculateDiscounts(totalCost);

                orderValidationStatus.IsValid = true;

                orderValidationStatus.OrderEntity = new OrderEntity()
                {
                    CustomerEntity = customer,
                    AccountEntity  = account,
                    OrderDate      = DateTime.Now,
                    OrderId        = ObjectId.GenerateNewId().ToString(),
                    OrderType      = FinalOrderType.Completed,
                    Products       = products,
                    TotalCost      = totalCost,
                    Interceptions  = logger.LogList,
                    Invokations    = invoker.InvokedList
                };

                SalesValidation salesValidation = new SalesValidation(new RepositoryFactory <SalesEntity>(), ConnString);
                var             salesEntity     = salesValidation.GetAllSales();

                if (orderValidationStatus.OrderEntity.CustomerEntity.SchemesCards.DrugScheme)
                {
                    salesEntity.SalesEntity.DrugSchemeSales++;
                }

                else if (orderValidationStatus.OrderEntity.CustomerEntity.SchemesCards.MedicalCard)
                {
                    salesEntity.SalesEntity.MedicalCardSales++;
                }

                else
                {
                    salesEntity.SalesEntity.RegularSales++;
                }

                salesValidation.UpdateSales(salesEntity.SalesEntity);

                return(orderValidationStatus);
            }

            return(orderValidationStatus);
        }