Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public async Task <ArticlesResponseModel> GetArticlesByStore(int id)
 {
     // get articles by store using linq
     try
     {
         ArticlesResponseModel response = new ArticlesResponseModel();
         var list = await(from d in _context.Articles
                          where d.Store_Id == id
                          select new ArticlesInformation()
         {
             Id             = d.Id,
             Description    = d.Description,
             Name           = d.Name,
             Price          = d.Price,
             Store_Id       = d.Store_Id,
             Total_In_Shelf = d.Total_In_Shelf,
             Total_In_Vault = d.Total_In_Vault
         }).ToListAsync();
         response = ArticlesResponseModel.Map(list);
         return(response);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 3
0
        public ArticlesResponseModel Create(List <Article> articles)
        {
            ArticlesResponseModel model = new ArticlesResponseModel();

            model.total_elements = articles.Count();
            model.articles       = articles.Select(a => Create(a)).ToList();

            return(model);
        }
Ejemplo n.º 4
0
        public async Task <ArticlesResponseModel> GetAllArticles()
        {
            //get all articles using ef code first context
            try
            {
                List <ArticlesInformation> articlesInformation = await _context.Articles.ToListAsync();

                ArticlesResponseModel articlesResponseModel = ArticlesResponseModel.Map(articlesInformation);
                return(articlesResponseModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var articles = await _articleProvider.GetAllAsync();

                var result = new ArticlesResponseModel(articles);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                var result = new FailureModel(success: true, code: (int)HttpStatusCode.BadRequest, response: "Bad Request");
                return(BadRequest(result));
            }
        }
Ejemplo n.º 6
0
        public async Task <ArticlesResponseModel> AddArticle(ArticlesInformation articlesInformation)
        {
            // update article using context and returning info using lambdas
            try
            {
                _context.Articles.Add(articlesInformation);
                await _context.SaveChangesAsync();

                List <ArticlesInformation> response = await _context.Articles.Where(x => x.Store_Id == articlesInformation.Store_Id).ToListAsync();

                ArticlesResponseModel articlesResponseModel = ArticlesResponseModel.Map(response);
                return(articlesResponseModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 7
0
        public async Task <ArticlesResponseModel> UpdateArticle(ArticlesInformation articlesInformation, ArticlesInformation originalInformation)
        {
            // update article using context and returning info using lambdas
            try
            {
                var updateInfo = ArticlesInformation.MapUpdate(articlesInformation, originalInformation);
                _context.Entry(updateInfo).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                List <ArticlesInformation> _articlesInformation = await _context.Articles.Where(x => x.Id == articlesInformation.Id).ToListAsync();

                ArticlesResponseModel articlesResponseModel = ArticlesResponseModel.Map(_articlesInformation);
                return(articlesResponseModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> GetByStore(long id)
        {
            try
            {
                if (id == 0)
                {
                    throw new Exception();
                }
                var article = await _articleProvider.GetByStoreId(id);

                var result = new ArticlesResponseModel(article);
                return(Ok(result));
            }
            catch (RecordNotFoundException)
            {
                var result = new FailureModel(success: false, code: (int)HttpStatusCode.NotFound, response: "Record Not Found");
                return(NotFound(result));
            }
            catch (Exception ex)
            {
                var result = new FailureModel(success: false, code: (int)HttpStatusCode.BadRequest, response: "Bad Request");
                return(BadRequest(result));
            }
        }