コード例 #1
0
ファイル: Program.cs プロジェクト: jova/Rent-a-Car
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:52935/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            Random   rand      = new Random();
            DateTime tempDate  = DateTime.Now;
            int      vehicleId = 5;

            HttpResponseMessage response = client.GetAsync("api/vehicles/" + vehicleId).Result;
            VehicleInformation  vehicle  = response.Content.ReadAsAsync <VehicleInformation>().Result;

            for (int i = 0; i < 6; i++)
            {
                tempDate = tempDate.AddDays(-1);
                LastKm lastKm = new LastKm();
                lastKm.Date      = tempDate;
                lastKm.vehicleId = vehicleId;
                lastKm.Km        = rand.Next(5000, 9000);

                response = client.PostAsJsonAsync("api/lastKms", lastKm).Result;

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    Console.WriteLine("added: " + (i + 1));
                }
            }

            Console.ReadKey();
        }
コード例 #2
0
 // POST api/lastKms
 public IHttpActionResult Post([FromBody] LastKm lastKm)
 {
     lastKmService.Add(lastKm);
     return(Ok(new { success = true }));
 }
コード例 #3
0
ファイル: LastKmManager.cs プロジェクト: jova/Rent-a-Car
 public void Add(LastKm lastKm)
 {
     lastKmDal.Add(lastKm);
 }