public bool DeleteStore(int storeId, ISystemResponse error) { bool deleted = false; try { using (DataContext) { Store store = DataContext.Stores.Find(storeId); if (store != null) { DataContext.Stores.Remove(store); DataContext.SaveChanges(); deleted = true; } } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al eliminar la tienda"; error.Exception = ex; } return(deleted); }
public Article GetArticle(int articleId, ISystemResponse error) { Article article = new Article(); try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("articleId", articleId.ToString()); parameters.Add("bit", "false"); string request = WebAPIClient.GetRequest("Articles", "Get", parameters, error); if (!string.IsNullOrEmpty(request) && !error.Error) { JavaScriptSerializer serializer = new JavaScriptSerializer(); ArticleResponseModel response = serializer.Deserialize <ArticleResponseModel>(request); if (response != null && !error.Error && response.article != null) { article = response.article; } } } catch (Exception ex) { error.Error = true; error.Message = "No se pudo obtener la informacion del articulo solicitado"; error.Exception = ex; } return(article); }
public bool UpdateStore(StoreModel store, ISystemResponse error) { bool updated = false; try { string request = WebAPIClient.PutRequest("Stores", "", store, error, new Dictionary <string, string>()); if (!string.IsNullOrEmpty(request) && !error.Error) { JavaScriptSerializer serializer = new JavaScriptSerializer(); BasicResponseModel response = serializer.Deserialize <BasicResponseModel>(request); if (response != null && !error.Error) { updated = response.success; } } } catch (Exception ex) { error.Error = true; error.Message = "No fue posible actualizar la tienda"; error.Exception = ex; } return(updated); }
public bool CreateArticle(Article article, ISystemResponse error) { bool created = false; try { string request = WebAPIClient.PostRequest("Articles", "", article, error, new Dictionary <string, string>()); if (!string.IsNullOrEmpty(request) && !error.Error) { JavaScriptSerializer serializer = new JavaScriptSerializer(); BasicResponseModel response = serializer.Deserialize <BasicResponseModel>(request); if (response != null && !error.Error) { created = response.success; } } } catch (Exception ex) { error.Error = true; error.Message = "No fue posible crear el articulo"; error.Exception = ex; } return(created); }
public bool DeleteArticle(int articleId, ISystemResponse error) { bool deleted = false; try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("articleId", articleId.ToString()); string request = WebAPIClient.DeleteRequest("Articles", "", error, parameters); if (!string.IsNullOrEmpty(request) && !error.Error) { JavaScriptSerializer serializer = new JavaScriptSerializer(); BasicResponseModel response = serializer.Deserialize <BasicResponseModel>(request); if (response != null && !error.Error) { deleted = response.success; } } } catch (Exception ex) { error.Error = true; error.Message = "No fue posible eliminar"; error.Exception = ex; } return(deleted); }
public bool DeleteArticle(int articleId, ISystemResponse error) { bool deleted = false; try { using (DataContext) { Article article = DataContext.Articles.Find(articleId); if (article != null) { DataContext.Articles.Remove(article); DataContext.SaveChanges(); deleted = true; } } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al eliminar el articulo"; error.Exception = ex; } return(deleted); }
public List <ArticleModel> GetArticles(ISystemResponse error) { List <ArticleModel> articles = new List <ArticleModel>(); try { string request = WebAPIClient.GetRequest("Articles", "Get", new Dictionary <string, string>(), error); if (!string.IsNullOrEmpty(request) && !error.Error) { JavaScriptSerializer serializer = new JavaScriptSerializer(); ArticlesResponseModel response = serializer.Deserialize <ArticlesResponseModel>(request); if (response != null && !error.Error && response.articles != null) { articles = response.articles; } } } catch (Exception ex) { error.Error = true; error.Message = "No se pudieron obtener los articulos"; error.Exception = ex; } return(articles); }
public bool UpdateArticle(Article article, ISystemResponse error) { bool updated = false; try { using (DataContext) { Article oldArticle = DataContext.Articles.Find(article.Id); if (oldArticle != null) { oldArticle.description = article.description; oldArticle.name = article.name; oldArticle.price = article.price; oldArticle.store_id = article.store_id; oldArticle.total_in_shelf = article.total_in_shelf; oldArticle.total_in_vault = article.total_in_vault; DataContext.SaveChanges(); updated = true; } } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al actualizar la tienda"; error.Exception = ex; } return(updated); }
public bool UpdateStore(Store store, ISystemResponse error) { bool updated = false; try { using (DataContext) { Store oldStore = DataContext.Stores.Find(store.Id); if (oldStore != null) { oldStore.address = store.address; oldStore.name = store.name; DataContext.SaveChanges(); updated = true; } } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al actualizar la tienda"; error.Exception = ex; } return(updated); }
public StoreModel GetStore(int storeId, ISystemResponse error) { StoreModel store = new StoreModel(); try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("storeId", storeId.ToString()); string request = WebAPIClient.GetRequest("Stores", "Get", parameters, error); if (!string.IsNullOrEmpty(request) && !error.Error) { JavaScriptSerializer serializer = new JavaScriptSerializer(); StoreResponseModel response = serializer.Deserialize <StoreResponseModel>(request); if (response != null && !error.Error && response.store != null) { store = response.store; } } } catch (Exception ex) { error.Error = true; error.Message = "No se pudo obtener la informacion de la tienda solicitada"; error.Exception = ex; } return(store); }
public List <Article> GetArticles(ISystemResponse error) { List <Article> articles = new List <Article>(); try { using (DataContext) { articles = DataContext.Articles.ToList(); } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al obtener los articulos"; error.Exception = ex; } return(articles); }
public Article GetArticleById(int articleId, ISystemResponse error) { Article article = new Article(); try { using (DataContext) { article = DataContext.Articles.Find(articleId); } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al obtener el articulo"; error.Exception = ex; } return(article); }
public Store GetStoreById(int storeId, ISystemResponse error) { Store store = new Store(); try { using (DataContext) { store = DataContext.Stores.Find(storeId); } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al obtener la tienda"; error.Exception = ex; } return(store); }
public List <Store> GetStores(ISystemResponse error) { List <Store> stores = new List <Store>(); try { using (DataContext) { stores = DataContext.Stores.ToList(); } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al obtener las tiendas"; error.Exception = ex; } return(stores); }
public List <Article> GetArticlesByStoreId(int storeId, ISystemResponse error) { List <Article> articles = new List <Article>(); try { using (DataContext) { articles = DataContext.Articles .Where(a => a.store_id == storeId) .ToList(); } } catch (Exception ex) { error.Error = true; error.Message = "Ocurrio un error al obtener los articulos de la tienda solicitada"; error.Exception = ex; } return(articles); }
public bool CreateArticle(Article article, ISystemResponse error) { bool created = false; try { using (DataContext) { DataContext.Articles.Add(article); DataContext.SaveChanges(); created = true; } } catch (Exception ex) { created = false; error.Error = true; error.Message = "Ocurrio un error al crear el articulo"; error.Exception = ex; } return(created); }
public bool CreateStore(Store store, ISystemResponse error) { bool created = false; try { using (DataContext) { DataContext.Stores.Add(store); DataContext.SaveChanges(); created = true; } } catch (Exception ex) { created = false; error.Error = true; error.Message = "Ocurrio un error al crear la tienda"; error.Exception = ex; } return(created); }
public static string GetRequest(string controllerName, string methodUrl, Dictionary <string, string> parametersDictionary, ISystemResponse error) { string response = null; string parameters = string.Empty; if (parametersDictionary.Count > 0) { parameters = "?"; int counter = 0; foreach (var item in parametersDictionary) { if (counter == (parametersDictionary.Count - 1)) { parameters += string.Format("{0}={1}", item.Key, item.Value); } else { parameters += string.Format("{0}={1}&", item.Key, item.Value); } counter++; } } string completeURL = string.Format("{0}{1}{2}", WebServiceUrl, controllerName, parameters); try { using (var client = new System.Net.WebClient()) { client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials); Stream stream = client.OpenRead(completeURL); StreamReader reader = new StreamReader(stream); response = reader.ReadToEnd(); } } catch (WebException webEx) { error.Error = true; error.Exception = webEx; if (webEx.Response is HttpWebResponse) { switch (((HttpWebResponse)webEx.Response).StatusCode) { case HttpStatusCode.NotFound: response = null; error.Message = "URL not found"; break; case HttpStatusCode.Forbidden: response = null; error.Message = "Access to the URL not allowed"; break; default: response = null; error.Message = "Exception ocurred while executing the Get request"; break; } } } catch (Exception ex) { error.Error = true; error.Exception = ex; error.Message = string.Concat("Exception ocurred while executing the Get request:", completeURL); response = null; } return(response); }
public static string DeleteRequest(string controllerName, string actionName, ISystemResponse error, Dictionary <string, string> parametersDictionary = null) { string response = null; string parameters = string.Empty; if (parametersDictionary.Count > 0) { parameters = "?"; int counter = 0; foreach (var item in parametersDictionary) { if (counter == (parametersDictionary.Count - 1)) { parameters += string.Format("{0}={1}", item.Key, item.Value); } else { parameters += string.Format("{0}={1}&", item.Key, item.Value); } counter++; } } string completeURL = string.Concat(WebServiceUrl, controllerName, "/", actionName, parameters); Uri completeUri = new Uri(completeURL); try { using (var client = new System.Net.WebClient()) { client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials); //client.Headers["Content-Type"] = "application/json"; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] byteArrayResponse = client.UploadValues(completeUri, "DELETE", new NameValueCollection()); response = System.Text.Encoding.UTF8.GetString(byteArrayResponse); } } catch (WebException webEx) { error.Error = true; error.Exception = webEx; if (webEx.Response is HttpWebResponse) { switch (((HttpWebResponse)webEx.Response).StatusCode) { case HttpStatusCode.NotFound: response = null; error.Message = "URL not found"; break; case HttpStatusCode.Forbidden: response = null; error.Message = "Access to the URL not allowed"; break; default: response = null; error.Message = "Exception ocurred while executing the PUT request to the service"; break; } } } catch (Exception ex) { error.Error = true; error.Exception = ex; error.Message = string.Concat("Exception ocurred while executing the PUT request to the service:", completeURL); response = null; } return(response); }