Example #1
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));
        }
Example #2
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));
        }
Example #3
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);
     }
 }