public void Update(KiralikBilgi obj)
 {
     if (obj != null)
     {
         contextNesnesi.Entry(obj).State = EntityState.Modified;
     }
 }
Exemple #2
0
        static async Task <Uri> CreateProductAsync(KiralikBilgi kiralik)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync(
                "api/KiralikBilgi", kiralik);

            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return(response.Headers.Location);
        }
Exemple #3
0
        static async Task <KiralikBilgi> GetProductAsync(string path)
        {
            KiralikBilgi        kiralik  = null;
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                kiralik = await response.Content.ReadAsAsync <KiralikBilgi>();
            }
            return(kiralik);
        }
Exemple #4
0
        static async Task <KiralikBilgi> UpdateProductAsync(KiralikBilgi kiralik)
        {
            HttpResponseMessage response = await client.PutAsJsonAsync(
                $"api/KiralikBilgi/{kiralik.AracID}", kiralik);

            response.EnsureSuccessStatusCode();

            // Deserialize the updated product from the response body.
            kiralik = await response.Content.ReadAsAsync <KiralikBilgi>();

            return(kiralik);
        }
Exemple #5
0
 public bool Ekle(KiralikBilgi entity)
 {
     try
     {
         Context.Set <KiralikBilgi>().Add(entity);
         Context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception("Business:AraclarBusiness::AracEkle::Error occured.", ex);
     }
 }
Exemple #6
0
        private async void btnKiralikBilgiEkle_Click(object sender, EventArgs e)
        {
            try
            {
                bool success = false;
                // Create a HttpClient
                using (var client = new HttpClient())
                {
                    // Setup basics
                    client.BaseAddress = new Uri("http://localhost:52009/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    decimal ucret = ((Convert.ToInt32(txtSon.Text) - Convert.ToInt32(txtAnlikKm.Text)) * 100);
                    // Create post body object
                    KiralikBilgi kiralik = new KiralikBilgi()
                    {
                        AracID          = Convert.ToInt16(txtAracID.Text),
                        KiralikID       = Convert.ToInt16(txtAracID.Text),
                        MusteriID       = Convert.ToInt16(txtMusteriID.Text),
                        BaslangicTarihi = Convert.ToDateTime(dateTimePicker1),
                        TeslimTarihi    = Convert.ToDateTime(dateTimePicker2),
                        AnlikKm         = Convert.ToInt32(txtAnlikKm.Text),
                        SonKm           = Convert.ToInt32(txtSon.Text),
                        AlinanUcret     = ucret
                    };

                    // Serialize C# object to Json Object
                    var serializedProduct = JsonConvert.SerializeObject(kiralik);
                    // Json object to System.Net.Http content type
                    var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                    // Post Request to the URI
                    var result = await client.PostAsync("api/KiralikBilgi", content);

                    // Check for result
                    if (result.IsSuccessStatusCode)
                    {
                        success = true;
                    }
                }
                // Set message depend on success info
                var message = success ? "done" : "failed";
                // Inform user
                MessageBox.Show("Operation " + message);
            }
            catch (Exception ex)
            {
                // Inform user
                MessageBox.Show("Error happened: " + ex.Message);
            }
        }
Exemple #7
0
        /*public static class HttpResponseMessageExtensions
         * {
         *  public static async Task EnsureSuccessStatusCodeAsync(this HttpResponseMessage response)
         *  {
         *      if (response.IsSuccessStatusCode)
         *      {
         *          return;
         *      }
         *
         *      var content = await response.Content.ReadAsStringAsync();
         *
         *      if (response.Content != null)
         *          response.Content.Dispose();
         *
         *      throw new SimpleHttpResponseException(response.StatusCode, content);
         *  }
         * }
         *
         * public class SimpleHttpResponseException : Exception
         * {
         *  public HttpStatusCode StatusCode { get; private set; }
         *
         *  public SimpleHttpResponseException(HttpStatusCode statusCode, string content) : base(content)
         *  {
         *      StatusCode = statusCode;
         *  }
         * }
         * public static void EnsureSuccessStatusCode(this HttpResponseMessage response)
         * {
         *  if (response.IsSuccessStatusCode)
         *  {
         *      return;
         *  }
         *
         *  var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
         *
         *  if (response.Content != null)
         *      response.Content.Dispose();
         *
         *  throw new SimpleHttpResponseException(response.StatusCode, content);
         * }*/

        static async Task RunAsync()
        {
            // Update port # in the following line.
            client.BaseAddress = new Uri("http://localhost:52009/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/problem+json"));

            try
            {
                // Create a new product
                KiralikBilgi kiralik = new KiralikBilgi
                {
                    KiralikID   = 6,
                    AracID      = 6,
                    AlinanUcret = 500
                };

                var url = await CreateProductAsync(kiralik);

                Console.WriteLine($"Created at {url}");

                // Get the product
                kiralik = await GetProductAsync(url.PathAndQuery);

                ShowProduct(kiralik);

                // Update the product
                Console.WriteLine("Updating price...");
                kiralik.AracID = 8;
                await UpdateProductAsync(kiralik);

                // Get the updated product
                kiralik = await GetProductAsync(url.PathAndQuery);

                ShowProduct(kiralik);

                // Delete the product
                var statusCode = await DeleteProductAsync(kiralik.KiralikID);

                Console.WriteLine($"Deleted (HTTP Status = {(int)statusCode})");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
Exemple #8
0
 public bool EkleKiralama(KiralikBilgi entity)
 {
     try
     {
         using (KiralikBilgiBusiness kiralikBilgiBusiness = new KiralikBilgiBusiness())
         {
             kiralikBilgiBusiness.Ekle(entity);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Insert(KiralikBilgi kiralikArac)
 {
     try
     {
         using (var nesne = new EfKiralikRepository())
         {
             nesne.Insert(kiralikArac);
             return(true);
         }
     }
     catch (Exception hata)
     {
         Console.WriteLine(hata);
         return(false);
     }
 }
 public bool Update(KiralikBilgi rentedCar)
 {
     try
     {
         using (var nesne = new EfKiralikRepository())
         {
             nesne.Update(rentedCar);
             return(true);
         }
     }
     catch (Exception hata)
     {
         Console.WriteLine(hata);
         return(false);
     }
 }
        public IHttpActionResult Post([FromBody] KiralikBilgi kiralikbilgi)
        {
            var content = new ResponseContent <KiralikBilgi>(null);

            if (kiralikbilgi != null)
            {
                using (var kiralikBilgiBusiness = new KiralikBilgiBusiness())
                {
                    content.Result = kiralikBilgiBusiness.Ekle(kiralikbilgi) ? "1" : "0";

                    return(new StandartResult <KiralikBilgi>(content, Request));
                }
            }

            content.Result = "0";

            return(new StandartResult <KiralikBilgi>(content, Request));
        }
 public void Update(KiralikBilgi kiralıkBilgi)
 {
     _kiralilBilgiDataAccesLayer.Update(kiralıkBilgi);
 }
 public void Add(KiralikBilgi kiralıkBilgi)
 {
     _kiralilBilgiDataAccesLayer.Add(kiralıkBilgi);
 }
 public void Insert(KiralikBilgi obj)
 {
     contextNesnesi.Kiralik.Add(obj);
 }
Exemple #15
0
 static void ShowProduct(KiralikBilgi kiralik)
 {
     Console.WriteLine($"KiralikID: {kiralik.KiralikID}\tAracID: " +
                       $"{kiralik.AracID}\tAlınanUcret: {kiralik.AlinanUcret}");
 }