Esempio n. 1
0
        public ArticlesResponse Articles(Articles articles)
        {
            ArticlesResponse ArticlesResponse = new ArticlesResponse();
            List <Articles>  ListaArticles    = new List <Articles>();

            try
            {
                if (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);
                }

                using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString))
                {
                    superZapatos.Articles.Add(articles);

                    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);
        }
Esempio n. 2
0
        public StoreResponse Stores(Stores stores)
        {
            StoreResponse StoreResponse = new StoreResponse();
            List <Stores> ListaStores   = new List <Stores>();

            try
            {
                if (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);
                }

                using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString))
                {
                    superZapatos.Stores.Add(stores);
                    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);
        }
Esempio n. 3
0
        public ArticlesResponse Articles(string id)
        {
            ArticlesResponse ArticlesResponse = new ArticlesResponse();
            List <Articles>  ListaArticles    = new List <Articles>();
            int idNumero;

            try
            {
                if (id == 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);
                }

                using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString))
                {
                    Articles articlesDelete = superZapatos.Articles.Find(idNumero);
                    if (articlesDelete == 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.Articles.Remove(articlesDelete);
                    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);
        }
Esempio n. 4
0
        public StoreResponse Stores(string id)
        {
            StoreResponse StoreResponse = new StoreResponse();
            List <Stores> ListaStores   = new List <Stores>();
            int           idNumero;

            try
            {
                if (id == 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);
                }

                using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString))
                {
                    Stores storesDelete = superZapatos.Stores.Find(idNumero);
                    if (storesDelete == 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);
                    }

                    superZapatos.Stores.Remove(storesDelete);
                    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);
        }