Ejemplo n.º 1
0
        public IHttpActionResult PutClient(int id, Client client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.OK));
        }
Ejemplo n.º 3
0
 public int CreateNewCategoryDB(string desc)
 {
     using (OrdersEntities db = new OrdersEntities()) //objeto creado tiempo de vida solo dentro  para no consumir memoria
     {
         Categories newCategory = new Categories();
         newCategory.Description = desc;
         //{ Description = desc }; //creando el mismo objeto de arriba de otra forma
         db.Categories.Add(newCategory);
         return(db.SaveChanges());
     }
 }
Ejemplo n.º 4
0
 public string Save(string model)
 {
     try
     {
         agents agent;
         var    context = System.Web.HttpContext.Current;
         agent = (agents)context.Cache["agent"];
         var log = new logsString {
             id = 0, agent = agent.agent, content = model, date = DateTime.Now
         };
         db.Entry(log).State = EntityState.Added;
         db.SaveChanges();
         var logs = new JavaScriptSerializer().Deserialize <log[]>(model);
         foreach (var item in logs)
         {
             item.timeStampServer = DateTime.Now;
             db.Entry(item).State = EntityState.Added;
             db.SaveChanges();
         }
         var orders = new JavaScriptSerializer().Deserialize <Order[]>(model);
         foreach (var a in orders.ToList())
         {
             foreach (var c in db.Orders.Where(o => o.agent == a.agent && o.customer == a.customer && o.number == a.number).ToList())
             {
                 db.Entry(c).State = EntityState.Deleted;
                 db.SaveChanges();
             }
         }
         foreach (var item in orders)
         {
             db.Entry(item).State = EntityState.Added;
             db.SaveChanges();
         }
         return("Записано");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
 public void DeleteProductDB(Products productApi)
 {
     db.Products.Remove(db.Products.Find(productApi.Id));
     db.SaveChanges();
 }
Ejemplo n.º 6
0
 public void DeleteCategoryDB(Categories categoryApi)
 {
     db.Categories.Remove(db.Categories.Find(categoryApi.Id));
     db.SaveChanges();
 }