Пример #1
0
 public void Update(T item)
 {
     using (OMDBEntities context = new OMDBEntities())
     {
         context.Set <T>().AddOrUpdate(item);
         context.SaveChanges();
     }
 }
Пример #2
0
 public void RemoveRange(Expression <Func <T, bool> > predicate)
 {
     using (OMDBEntities context = new OMDBEntities())
     {
         context.Set <T>().RemoveRange(context.Set <T>().Where(predicate));
         context.SaveChanges();
     }
 }
Пример #3
0
 public void Add(List <T> items)
 {
     using (OMDBEntities context = new OMDBEntities())
     {
         context.Set <T>().AddRange(items);
         context.SaveChanges();
     }
 }
Пример #4
0
 public void Remove(int id)
 {
     using (OMDBEntities context = new OMDBEntities())
     {
         T item = context.Set <T>().Find(id);
         if (item != null)
         {
             context.Set <T>().Remove(item);
             context.SaveChanges();
         }
     }
 }
Пример #5
0
 public void Add(T item)
 {
     using (OMDBEntities context = new OMDBEntities())
     {
         try
         {
             context.Set <T>().Add(item);
             context.SaveChanges();
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
 // POST: api/Product
 public HttpResponseMessage Post([FromBody] Product value)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (OMDBEntities Productdetails = new OMDBEntities())
             {
                 Productdetails.Products.Add(value);
                 Productdetails.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Invalid Model"));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }