Esempio n. 1
0
        public IActionResult AddRent([FromBody] CustomerRentInfo data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                long customerId = 1;
                if (!Helpers.CheckBalance())
                {
                    return(BadRequest("not enought balance"));
                }

                Helpers.CalculateRent(data);
                WebRequest.SendWebRequest(urls.AddRent, "POST", JsonConvert.SerializeObject(new { customerId, RentedData = data }));
                return(Ok());
            }
            catch (Exception ex)
            {
                logger.LogError("Add rent action " + ex.Message);
            }

            return(BadRequest());
        }
Esempio n. 2
0
        public static void CalculateRent(CustomerRentInfo rentedData)
        {
            var OneTimePrice = 100;
            var PremiumPrice = 60;
            var RegularPrice = 40;

            switch (rentedData.CustomerRentedProduct)
            {
            case ProductType.Heavy:
                rentedData.CustomerPoints    = 2;
                rentedData.CustomerPaidMoney = OneTimePrice + (rentedData.RentalPeriod * PremiumPrice);
                break;

            case ProductType.Regular:
                rentedData.CustomerPoints = 1;

                rentedData.CustomerPaidMoney = rentedData.RentalPeriod > 2 ?
                                               100 + (2 * PremiumPrice) + ((rentedData.RentalPeriod - 2) * RegularPrice) :
                                               100 + (rentedData.RentalPeriod * PremiumPrice);
                break;

            case ProductType.Specialized:
                rentedData.CustomerPoints    = 1;
                rentedData.CustomerPaidMoney = rentedData.RentalPeriod > 3 ?
                                               (rentedData.RentalPeriod * PremiumPrice) :
                                               (3 * PremiumPrice) + ((rentedData.RentalPeriod - 3) * RegularPrice);
                break;
            }
        }
        public void TestAddRent()
        {
            long             customerId       = 1;
            CustomerRentInfo customerRentInfo = new CustomerRentInfo()
            {
                CustomerPaidMoney = 100, CustomerPCType = "Chrome", CustomerPoints = 2, CustomerRentedProduct = ProductType.Heavy, Name = "Bulduser", RentalPeriod = 1
            };

            Assert.True(manager.AddRent(customerId, customerRentInfo));
        }
Esempio n. 4
0
        public bool AddRent(long custumerId, CustomerRentInfo rentedData)
        {
            bool IsAdded      = false;
            var  customerData = new Dictionary <long, List <CustomerRentInfo> >();

            if (_cache.TryGetValue("CustomerData", out customerData))
            {
                if (customerData.ContainsKey(custumerId))
                {
                    customerData[custumerId].Add(rentedData);
                    IsAdded = true;
                }
                else
                {
                    customerData.Add(custumerId, new List <CustomerRentInfo>()
                    {
                        rentedData
                    });
                    IsAdded = true;
                }
            }

            return(IsAdded);
        }
 public bool AddRent(long customerId, CustomerRentInfo rentedData)
 {
     return(cacheMemoryService.AddRent(customerId, rentedData));
 }