Пример #1
0
 public string BuyBook([FromBody] BuyBookModel model)
 {
     if (model.DeliveryService == "Motorbike")
     {
         DateTime deliveryDate = DateTime.Now.AddDays(random.Next(0, 7));
         return(DeliveryInfoGenerator.Generate(new MotorbikeDeliveryInfo
         {
             Driver = RandomString(random.Next(5, 15)),
             Mobile = random.Next(640000000, 649999999).ToString(),
             DeliveryCost = DeliveryCostCalculator.GetCost(DeliveryType.Motorbike, deliveryDate),
             DeliveryDate = deliveryDate
         }));
     }
     else if (model.DeliveryService == "Train")
     {
         DateTime arrivalDate = DateTime.Now.AddDays(random.Next(1, 7));
         return(DeliveryInfoGenerator.Generate(new TrainDeliveryInfo
         {
             TrainNo = random.Next(100, 999).ToString(),
             ArrivalDate = arrivalDate,
             DeliveryCost = DeliveryCostCalculator.GetCost(DeliveryType.Train, arrivalDate),
             StationName = RandomString(random.Next(5, 15))
         }));
     }
     else if (model.DeliveryService == "Aircraft")
     {
         DateTime arrivalDate = DateTime.Now.AddDays(random.Next(0, 3));
         return(DeliveryInfoGenerator.Generate(new AircraftDeliveryInfo
         {
             FlightNo = random.Next(100, 999).ToString(),
             ArrivalDate = arrivalDate,
             DeliveryCost = DeliveryCostCalculator.GetCost(DeliveryType.Aircraft, arrivalDate),
             GateNumber = random.Next(1, 500).ToString()
         }));
     }
     else
     {
         throw new Exception("Wrong delivery service");
     }
 }