Пример #1
0
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EmpId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
 public void UpdateProduct(int id, Product product)
 {
     using (var swarnacontext = new SwarnaContext())
     {
         swarnacontext.Entry(product).State = EntityState.Modified;
         try
         {
             swarnacontext.SaveChanges();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!ProductExists(id))
             {
                 //return NotFound();
             }
             else
             {
                 throw;
             }
         }
     }
 }