예제 #1
0
        public StoreResponse Stores()
        {
            StoreResponse StoreResponse = new StoreResponse();
            List <Stores> ListaStores   = new List <Stores>();

            try
            {
                using (DbContextSuperZapatos superZapatos = new DbContextSuperZapatos(connectionString))
                {
                    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);
        }
예제 #2
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);
        }
예제 #3
0
        public ArticlesResponse ArticlesStores(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))
                {
                    superZapatos.Stores.ToList();
                    ListaArticles = superZapatos.Articles.Where(n => n.store_id == idNumero).ToList();
                }

                if (ListaArticles.Count > 0)
                {
                    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;
                }
                else
                {
                    ArticlesResponse.articles       = new List <ApiArticles>();
                    ArticlesResponse.total_elements = 0;
                    ArticlesResponse.success        = false;
                    ArticlesResponse.error_code     = 404;
                    ArticlesResponse.error_msg      = "Record not Found";
                }
            }
            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);
        }
예제 #4
0
        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);
        }
예제 #5
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);
        }