Ejemplo n.º 1
0
        // PUT api/<controller>/5
        public HttpResponseMessage Put(int id, BaseTea baseTea)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != baseTea.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(baseTea).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        private async void BtnUpdateBaseTea_Click(object sender, RoutedEventArgs e)
        {
            if (BaseTeaIsEmpty())
            {
                return;
            }

            try
            {
                var baseTea = new BaseTea()
                {
                    Id   = (int)LblBaseTeaId.Content,
                    Name = TxtBaseTeaName.Text
                };

                var response = await _client.PutAsJsonAsync(Constants.BaseTeaAddress + baseTea.Id, baseTea);

                response.EnsureSuccessStatusCode();
                LoadDataBaseTea();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Constants.GeneralError);
            }
        }
Ejemplo n.º 3
0
 private void DataBaseTea_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (DataBaseTea.SelectedItem != null && DataBaseTea.SelectedItem.GetType() == typeof(BaseTea))
     {
         BaseTea selectedBaseTea = (BaseTea)DataBaseTea.SelectedItem;
         TxtBaseTeaName.Text  = selectedBaseTea.Name;
         LblBaseTeaId.Content = selectedBaseTea.Id;
     }
 }
Ejemplo n.º 4
0
        // GET api/<controller>/5
        public BaseTea Get(int id)
        {
            BaseTea baseTea = db.BaseTeas.Find(id);

            if (baseTea == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(baseTea);
        }
Ejemplo n.º 5
0
        // POST api/<controller>
        public HttpResponseMessage Post(BaseTea baseTea)
        {
            if (ModelState.IsValid)
            {
                db.BaseTeas.Add(baseTea);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, baseTea);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = baseTea.Id }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Ejemplo n.º 6
0
        // DELETE api/<controller>/5
        public HttpResponseMessage Delete(int id)
        {
            BaseTea baseTea = db.BaseTeas.Find(id);

            if (baseTea == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.BaseTeas.Remove(baseTea);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, baseTea));
        }