コード例 #1
0
        public HttpResponseMessage AddArticles([FromBody] ArticleRequest article)
        {
            try
            {
                using (BackNetEntity db = new BackNetEntity())
                {
                    var oArticle = new Models.articles();
                    oArticle.name           = article.name;
                    oArticle.description    = article.description;
                    oArticle.price          = article.price;
                    oArticle.total_in_shelf = article.total_in_shelf;
                    oArticle.total_in_vault = article.total_in_vault;
                    oArticle.store_id       = article.store_id;
                    db.articles.Add(oArticle);
                    db.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, article);
                    message.Headers.Location = new Uri(Request.RequestUri +
                                                       article.id.ToString());

                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
コード例 #2
0
 public HttpResponseMessage DelArticles(int id)
 {
     try
     {
         using (BackNetEntity db = new BackNetEntity())
         {
             articles oArticles = db.articles.Find(id);
             if (oArticles == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "La Store con el Id " + id.ToString() + " no pudo Eliminarse"));
             }
             else
             {
                 db.articles.Remove(oArticles);
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #3
0
 public HttpResponseMessage PutStores(StoresRequest oModel)
 {
     try
     {
         using (BackNetEntity db = new BackNetEntity())
         {
             stores oStore = db.stores.Find(oModel.id);
             if (oStore == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "La Store con el Id " + oModel.id.ToString() + " no pudo actualizarse"));
             }
             else
             {
                 oStore.name            = oModel.name;
                 oStore.address         = oModel.address;
                 db.Entry(oStore).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #4
0
 public HttpResponseMessage PutArticles(ArticleRequest oModel)
 {
     try
     {
         using (BackNetEntity db = new BackNetEntity())
         {
             articles oArticles = db.articles.Find(oModel.id);
             if (oArticles == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "La Store con el Id " + oModel.id.ToString() + " no pudo actualizarse"));
             }
             else
             {
                 oArticles.name            = oModel.name;
                 oArticles.description     = oModel.description;
                 oArticles.price           = oModel.price;
                 oArticles.total_in_shelf  = oModel.total_in_shelf;
                 oArticles.total_in_vault  = oModel.total_in_vault;
                 oArticles.store_id        = oModel.store_id;
                 db.Entry(oArticles).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #5
0
        public HttpResponseMessage AddStores([FromBody] StoresRequest store)
        {
            try
            {
                using (BackNetEntity db = new BackNetEntity())
                {
                    var oStores = new Models.stores();
                    oStores.name    = store.name;
                    oStores.address = store.address;
                    db.stores.Add(oStores);
                    db.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, store);
                    message.Headers.Location = new Uri(Request.RequestUri +
                                                       store.id.ToString());

                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }