public ArticlesResponse Articles(string id, Articles articles) { ArticlesResponse ArticlesResponse = new ArticlesResponse(); List <Articles> ListaArticles = new List <Articles>(); int idNumero; try { if (id == null || articles == null) { ArticlesResponse.articles = new List <ApiArticles>(); ArticlesResponse.total_elements = 0; ArticlesResponse.success = false; ArticlesResponse.error_code = 400; ArticlesResponse.error_msg = "Bad Request"; return(ArticlesResponse); } bool esNumero = Int32.TryParse(id, out idNumero); if (!esNumero) { ArticlesResponse.articles = new List <ApiArticles>(); ArticlesResponse.total_elements = 0; ArticlesResponse.success = false; ArticlesResponse.error_code = 400; ArticlesResponse.error_msg = "Bad Request"; return(ArticlesResponse); } if (idNumero != articles.id) { ArticlesResponse.articles = new List <ApiArticles>(); ArticlesResponse.total_elements = 0; ArticlesResponse.success = false; ArticlesResponse.error_code = 400; ArticlesResponse.error_msg = "Bad Request"; return(ArticlesResponse); } using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString)) { Stores storeEdit = superZapatos.Stores.Find(articles.store_id); Articles articlesEdit = superZapatos.Articles.Find(idNumero); if (articlesEdit == null) { ArticlesResponse.articles = new List <ApiArticles>(); ArticlesResponse.total_elements = 0; ArticlesResponse.success = false; ArticlesResponse.error_code = 404; ArticlesResponse.error_msg = "Record not Found"; return(ArticlesResponse); } superZapatos.Entry(articlesEdit).State = EntityState.Detached; superZapatos.Entry(articles).State = EntityState.Modified; superZapatos.SaveChanges(); superZapatos.Stores.ToList(); ListaArticles = superZapatos.Articles.ToList(); } ArticlesResponse.articles = (from a in ListaArticles select new ApiArticles { id = a.id, name = a.name, description = a.description, price = a.price, total_in_vault = a.total_in_vault, total_in_shelf = a.total_in_shelf, store_id = a.store_id, store_name = a.store.name } ).ToList(); ArticlesResponse.total_elements = ListaArticles.Count; ArticlesResponse.success = true; ArticlesResponse.error_code = 0; ArticlesResponse.error_msg = string.Empty; } catch (Exception ex) { ArticlesResponse.articles = new List <ApiArticles>(); ArticlesResponse.total_elements = 0; ArticlesResponse.success = false; ArticlesResponse.error_code = 500; ArticlesResponse.error_msg = "Server Error"; log.Error(ex.Message); } return(ArticlesResponse); }
public StoreResponse Stores(string id, Stores stores) { StoreResponse StoreResponse = new StoreResponse(); List <Stores> ListaStores = new List <Stores>(); int idNumero; try { if (id == null || stores == null) { StoreResponse.stores = new List <Stores>(); StoreResponse.total_elements = 0; StoreResponse.success = false; StoreResponse.error_code = 400; StoreResponse.error_msg = "Bad Request"; return(StoreResponse); } bool esNumero = Int32.TryParse(id, out idNumero); if (!esNumero) { StoreResponse.stores = new List <Stores>(); StoreResponse.total_elements = 0; StoreResponse.success = false; StoreResponse.error_code = 400; StoreResponse.error_msg = "Bad Request"; return(StoreResponse); } if (idNumero != stores.id) { StoreResponse.stores = new List <Stores>(); StoreResponse.total_elements = 0; StoreResponse.success = false; StoreResponse.error_code = 400; StoreResponse.error_msg = "Bad Request"; return(StoreResponse); } using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString)) { Stores storesEdit = superZapatos.Stores.Find(idNumero); if (storesEdit == null) { StoreResponse.stores = new List <Stores>(); StoreResponse.total_elements = 0; StoreResponse.success = false; StoreResponse.error_code = 404; StoreResponse.error_msg = "Record not Found"; return(StoreResponse); } //storesEdit = stores; superZapatos.Entry(storesEdit).State = EntityState.Detached; superZapatos.Entry(stores).State = EntityState.Modified; superZapatos.SaveChanges(); ListaStores = superZapatos.Stores.ToList(); } StoreResponse.stores = ListaStores; StoreResponse.total_elements = ListaStores.Count; StoreResponse.success = true; StoreResponse.error_code = 0; StoreResponse.error_msg = string.Empty; } catch (Exception ex) { StoreResponse.stores = new List <Stores>(); StoreResponse.total_elements = 0; StoreResponse.success = false; StoreResponse.error_code = 500; StoreResponse.error_msg = "Server Error"; log.Error(ex.Message); } return(StoreResponse); }