Пример #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 Product AddProduct(Product prod)
 {
     using (var swarnacontext = new SwarnaContext())
     {
         swarnacontext.Products.Add(prod);
         swarnacontext.SaveChanges();
         return(prod);
     }
 }
Пример #3
0
        public Product DeleteProduct(int id)
        {
            SwarnaContext swarnacontext = new SwarnaContext();
            Product       product       = swarnacontext.Products.Find(id);

            if (product == null)
            {
                //return NotFound();
            }

            swarnacontext.Products.Remove(product);
            swarnacontext.SaveChanges();
            return(product);
        }
Пример #4
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;
             }
         }
     }
 }