コード例 #1
0
        public ApiResponse UpdateArticle([FromBody] ArticleDTO article)
        {
            SystemFail  error    = new SystemFail();
            ApiResponse response = new ApiResponse();

            if (ModelState.IsValid)
            {
                Article updatedArticle = TransformArticleDTOtoArticle(article);
                articleService.UpdateArticle(updatedArticle, error);
                if (!error.Error)
                {
                    response.Message = "El articulo fue actualizado exitosamente.";
                    response.success = true;
                }
                else
                {
                    response.Message = string.Concat("No fue posible actualizar el articulo. Error: ", error.Message);
                    response.success = false;
                }
            }
            else
            {
                response.Message = string.Concat("Ha ocurrido un error al validar la entidad. Error:", string.Join(";", ModelState.Values.Select(x => x.Errors.Select(e => e.ErrorMessage))));
                response.success = false;
            }

            return(response);
        }
コード例 #2
0
        public ApiResponse DeleteStore([FromBody] StoreDTO store)
        {
            SystemFail  error    = new SystemFail();
            ApiResponse response = new ApiResponse();

            if (store != null && !error.Error)
            {
                Store deletStore = new Store();
                deletStore.Id      = store.Id;
                deletStore.Name    = store.Name;
                deletStore.Address = store.Address;
                storeService.DeleteStore(deletStore, error);
                if (!error.Error)
                {
                    response.Message = "La tienda fue eliminada exitosamente.";
                    response.success = true;
                }
                else
                {
                    response.Message = string.Concat("No fue posible eliminar la tienda. Error: ", error.Message);
                    response.success = false;
                }
            }
            else
            {
                response.Message = "Ha ocurrido un error. La tienda con el Id especificado , no fue encontrada";
                response.success = false;
            }
            return(response);
        }
コード例 #3
0
        public ApiResponse Post([FromBody] ArticleDTO article, string dummy)
        {
            SystemFail  error    = new SystemFail();
            ApiResponse response = new ApiResponse();

            if (ModelState.IsValid)
            {
                Article newArticle = TransformArticleDTOtoArticle(article);

                articleService.CreateArticle(newArticle, error);
                if (!error.Error)
                {
                    response.success = true;
                    response.Message = "Se creo correctamente el articulo";
                }
                else
                {
                    response.success = false;
                    response.Message = string.Concat("Ha ocurrido un error. Error:", error.Message);
                }
            }
            else
            {
                response.success = false;
                response.Message = string.Concat("Ha ocurrido un error al validar la entidad. Error:", string.Join(";", ModelState.Values.Select(x => x.Errors.Select(e => e.ErrorMessage))));
            }

            return(response);
        }
コード例 #4
0
        public ApiResponse DeleteArticle([FromBody] Article article)
        {
            SystemFail  error    = new SystemFail();
            ApiResponse response = new ApiResponse();

            if (article != null && !error.Error)
            {
                articleService.DeleteArticle(article, error);
                if (!error.Error)
                {
                    response.Message = "El articulo fue eliminada exitosamente.";
                    response.success = true;
                }
                else
                {
                    response.Message = string.Concat("No fue posible eliminar el articulo. Error: ", error.Message);
                    response.success = false;
                }
            }
            else
            {
                response.Message = "Ha ocurrido un error. El articulo con el Id especificado , no fue encontrado";
                response.success = false;
            }
            return(response);
        }
コード例 #5
0
        // GET: Store/Details/5
        public ActionResult Details(int id)
        {
            SystemFail error = new SystemFail();
            Store      store = StoreBLL.GetStoreById(id, error);

            return(View(store));
        }
コード例 #6
0
        public ApiResponse CreateStore([FromBody] StoreDTO store, string dummy)
        {
            SystemFail  error    = new SystemFail();
            ApiResponse response = new ApiResponse();

            if (ModelState.IsValid)
            {
                Store newStore = new Store();
                newStore.Address = store.Address;
                newStore.Id      = store.Id;
                newStore.Name    = store.Name;
                storeService.CreateStore(newStore, error);
                if (!error.Error)
                {
                    response.success = true;
                    response.Message = "Se creo correctamente la tienda";
                }
                else
                {
                    response.success = false;
                    response.Message = string.Concat("Ha ocurrido un error. Error:", error.Message);
                }
            }
            else
            {
                response.success = false;
                response.Message = string.Concat("Ha ocurrido un error al validar la entidad. Error:", string.Join(";", ModelState.Values.Select(x => x.Errors.Select(e => e.ErrorMessage))));
            }

            return(response);
        }
コード例 #7
0
        public ApiResponse UpdateStore([FromBody] StoreDTO store)
        {
            SystemFail  error    = new SystemFail();
            ApiResponse response = new ApiResponse();

            if (ModelState.IsValid)
            {
                Store updatedStore = new Store();
                updatedStore.Address = store.Address;
                updatedStore.Id      = store.Id;
                updatedStore.Name    = store.Name;
                storeService.UpdateStore(updatedStore, error);
                if (!error.Error)
                {
                    response.Message = "La tienda fue actualizada exitosamente.";
                    response.success = true;
                }
                else
                {
                    response.Message = string.Concat("No fue posible actualizar la tienda. Error: ", error.Message);
                    response.success = false;
                }
            }
            else
            {
                response.Message = string.Concat("Ha ocurrido un error al validar la entidad. Error:", string.Join(";", ModelState.Values.Select(x => x.Errors.Select(e => e.ErrorMessage))));
                response.success = false;
            }

            return(response);
        }
コード例 #8
0
        // GET: Article/Edit/5
        public ActionResult Edit(int id)
        {
            SystemFail error   = new SystemFail();
            Article    article = ArticleBLL.GetArticleById(id, error);


            return(View(article));
        }
コード例 #9
0
        // GET: Article/Create
        public ActionResult Create()
        {
            SystemFail   error  = new SystemFail();
            List <Store> stores = StoreBLL.GetAllStores(error);

            if (stores != null && !error.Error)
            {
                ViewBag.Stores = stores.Select(x => new { Id = x.Id, Name = x.Name });
            }

            return(View());
        }
コード例 #10
0
        // GET: Store
        public ActionResult Index()
        {
            SystemFail   error  = new SystemFail();
            List <Store> stores = StoreBLL.GetAllStores(error);

            if (stores == null && error.Error)
            {
                ViewBag.StartUpScript = string.Concat("An error has ocurred. Error", error.Message);
            }

            return(View(stores));
        }
コード例 #11
0
        // GET: Store/Edit/5
        public ActionResult Edit(int id)
        {
            SystemFail error   = new SystemFail();
            Store      article = StoreBLL.GetStoreById(id, error);

            if (article == null && error.Error)
            {
                TempData["StartUp"] = "$.notify('The Store with the specific ID wasn´t found','success')";
                return(RedirectToAction("Index"));
            }
            return(View(article));
        }
コード例 #12
0
        // GET: Article
        public ActionResult Index()
        {
            SystemFail error = new SystemFail();

            if (TempData["StartUpScript"] != null)
            {
                ViewBag.StartupScript = TempData["StartUpScript"].ToString();
            }


            List <Article> articles = ArticleBLL.GetAllArticles(error);

            return(View(articles));
        }
コード例 #13
0
        // GET: Article/Delete/5
        public ActionResult Delete(int id)
        {
            SystemFail error = new SystemFail();

            ArticleBLL.DeleteArticle(id, error);
            if (!error.Error)
            {
                TempData["StartUpScript"] = "$.notify('Se elimino correctamente el articulo','success');";
            }
            else
            {
                TempData["StartUpScript"] = "$.notify('" + error.Message + "','error');";
            }
            return(RedirectToAction("Index"));
        }
コード例 #14
0
        // GET: Store/Delete/5
        public ActionResult Delete(int id)
        {
            SystemFail error = new SystemFail();

            StoreBLL.DeleteStore(id, error);
            if (!error.Error)
            {
                TempData["StartUpScript"] = "$.notify('" + error.Message + "','success');";
            }
            else
            {
                TempData["StartUpScript"] = "$.notify('" + error.Message + "','error');";
            }
            return(RedirectToAction("Index"));
        }
コード例 #15
0
        public GetAllStoresResponse Get()
        {
            SystemFail           error    = new SystemFail();
            List <Store>         stores   = storeService.GetAllStores(error).ToList();
            GetAllStoresResponse response = new GetAllStoresResponse();

            response.success        = !error.Error;
            response.total_elements = stores.Count;
            response.stores         = stores.Select(x => new StoreDTO()
            {
                Id      = x.Id,
                Name    = x.Name,
                Address = x.Address
            }).ToList();

            return(response);
        }
コード例 #16
0
        public GetArticleByIdResponse GetArticleById(int articleId)
        {
            SystemFail             error    = new SystemFail();
            GetArticleByIdResponse response = new GetArticleByIdResponse();
            Article    article = articleService.GetArticleById(articleId, error);
            ArticleDTO dto     = new ArticleDTO();

            dto.Description  = article.Description;
            dto.Id           = article.Id;
            dto.Name         = article.Name;
            dto.Price        = article.Price;
            dto.StoreId      = article.StoreId;
            dto.TotalInShelf = article.TotalInShelf;
            dto.TotalInVault = article.TotalInVault;

            response.success = !error.Error;
            response.article = dto;
            return(response);
        }
コード例 #17
0
        public GetStoreByIdResponse GetStoreById(int id)
        {
            GetStoreByIdResponse response = new GetStoreByIdResponse();
            SystemFail           error    = new SystemFail();
            Store store = storeService.GetStoreById(id, error);

            if (store != null && !error.Error)
            {
                response.store         = new StoreDTO();
                response.store.Address = store.Address;
                response.store.Id      = store.Id;
                response.store.Name    = store.Name;
                response.success       = true;
            }
            else
            {
                response.success = false;
            }

            return(response);
        }
コード例 #18
0
        public GetAllArticleResponse GetStoreArticles(int id, string dummy)
        {
            SystemFail            error    = new SystemFail();
            List <Article>        articles = articleService.GettStoreArticles(id, error).ToList();
            GetAllArticleResponse response = new GetAllArticleResponse();

            response.success        = !error.Error;
            response.total_elements = articles.Count;
            response.articles       = articles.Select(x => new ArticleDTO()
            {
                Id           = x.Id,
                Name         = x.Name,
                Description  = x.Description,
                Price        = x.Price,
                StoreId      = x.StoreId,
                TotalInShelf = x.TotalInShelf,
                TotalInVault = x.TotalInVault
            }).ToList();

            return(response);
        }
コード例 #19
0
        public ActionResult Edit(Article model)
        {
            SystemFail error = new SystemFail();

            if (ModelState.IsValid)
            {
                ArticleBLL.UpdateArticle(model, error);
                if (!error.Error)
                {
                    TempData["StartUpScript"] = "$.notify('Se creo correctamente el articulo','success');";
                }
                else
                {
                    ViewBag.StartupScript = "$.notify('Ocurrio un error al crear el articulo.Error" + error.Message + "','error');";
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
            return(RedirectToAction("Index"));
        }
コード例 #20
0
        public ActionResult Edit(Store model)
        {
            SystemFail error = new SystemFail();

            if (ModelState.IsValid)
            {
                StoreBLL.UpdateStore(model, error);
                if (!error.Error)
                {
                    TempData["StartUpScript"] = "$.notify('" + error.Message + "','success');";
                }
                else
                {
                    ViewBag.StartupScript = "$.notify('" + error.Message + "','error');";
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
            return(RedirectToAction("Index"));
        }
コード例 #21
0
        public ActionResult Create(Article article)
        {
            SystemFail error = new SystemFail();

            if (ModelState.IsValid)
            {
                ArticleBLL.CreateArticle(article, error);
                if (!error.Error)
                {
                    TempData["StartUpScript"] = "$.notify('Se creo correctamente el articulo','success');";
                }
                else
                {
                    TempData["StartUpScript"] = "$.notify('Ocurrio un error al crear el articulo  Error" + error.Message + "','error');";
                }
            }
            else
            {
                ViewBag.StartupScript = "$.notify('Se han encontrador errores en la información ingresada. Por favor revisela','warn')";
                return(View(article));
            }

            return(RedirectToAction("Index"));
        }
コード例 #22
0
        public ActionResult Create(Store model)
        {
            SystemFail error = new SystemFail();

            if (ModelState.IsValid)
            {
                StoreBLL.CreateStore(model, error);
                if (!error.Error)
                {
                    TempData["StartUpScript"] = "$.notify('" + error.Message + "','success');";
                }
                else
                {
                    TempData["StartUpScript"] = "$.notify('" + error.Message + "','error');";
                }
            }
            else
            {
                ViewBag.StartupScript = "$.notify('Some errores were found in the formulary information. Please check it','warn')";
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }