Esempio n. 1
0
 public static ArticlesInformation MapUpdate(ArticlesInformation updated, ArticlesInformation original)
 {
     return(new ArticlesInformation
     {
         Id = updated.Id,
         Description = updated.Description != string.Empty ? updated.Description : original.Description,
         Name = updated.Name != string.Empty ? updated.Name : original.Description,
         Price = updated.Price.HasValue ? updated.Price : original.Price,
         Total_In_Shelf = updated.Total_In_Shelf.HasValue ? updated.Total_In_Shelf : original.Total_In_Shelf,
         Total_In_Vault = updated.Total_In_Vault.HasValue ? updated.Total_In_Vault : original.Total_In_Vault,
         Store_Id = updated.Store_Id.HasValue ? updated.Store_Id : original.Store_Id
     });
 }
Esempio n. 2
0
        public async Task <IActionResult> UpdateArticle(int id, ArticlesInformation articlesInformation)
        {
            // find article to update if not return not found
            var findArticle = _context.Articles.Find(id);

            if (findArticle == null)
            {
                return(NotFound());
            }
            // detach to use again later on dataset
            _context.Entry(findArticle).State = EntityState.Detached;
            try
            {
                return(Ok(await _articlesServices.UpdateArticle(articlesInformation, findArticle)));
            }
            catch (Exception e)
            {
                return(BadRequest(ErrorResponse.Map(e)));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> AddArticle(ArticlesInformation articlesInformation)
        {
            // find store to add article if not return not found
            var findStore = _context.Stores.Find(articlesInformation.Store_Id);

            if (findStore == null)
            {
                return(NotFound());
            }

            try
            {
                var response = await _articlesServices.AddArticle(articlesInformation);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(BadRequest(ErrorResponse.Map(e)));
            }
        }