Exemplo n.º 1
0
 public void SaveProduct(Product entity)
 {
     if (entity.Id == default)
     {
         context.Entry(entity).State = EntityState.Added;// объект будет добавлен как новый
     }
     else
     {
         context.Entry(entity).State = EntityState.Modified;// старый объект будет изменён
     }
     context.SaveChanges();
 }
Exemplo n.º 2
0
        public async Task <IActionResult> PutPayment([FromRoute] int id, [FromBody] Payment payment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != payment.PaymentId)
            {
                return(BadRequest());
            }

            _context.Entry(payment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaymentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public IHttpActionResult PutPizza(int id, Pizza pizza)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pizza.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PizzaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Ingredient ingredient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ingredient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ingredient));
 }