コード例 #1
0
        public async Task <ActionResult> Create(Articles_Create_VM vm)
        {
            ViewBag.ErrorMsg = "Ocurrió un error al tratar de obtener la tienda.";

            try
            {
                vm.Article.Store = new Store {
                    id = vm.StoresSelectedID
                };
                var response = await ArticlesServices.PostArticlesAsync(vm.Article);

                if (response.success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
            catch
            {
                return(View("Error"));
            }
        }
コード例 #2
0
        // GET: Articles/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            try
            {
                var response = await ArticlesServices.GetArticleAsync((int)id);

                var vm = new Articles_Create_VM(response.article);
                if (response.success)
                {
                    return(View(vm));
                }
                else
                {
                    ViewBag.ErrorMsg = "Ocurrió un error al tratar de obtener el artículo.";
                    return(View("Error"));
                }
            }
            catch (Exception)
            {
                ViewBag.ErrorMsg = "Ocurrió un error al tratar de editar el artículo.";
                return(View("Error"));
            }
        }
コード例 #3
0
        /// <summary>
        /// Metodo para cargar la grilla
        /// </summary>

        private void LoadGrid()
        {
            dgArticles.DataSource = null;

            ArticlesServices articlesManager = new ArticlesServices();

            var result = articlesManager.GetAll();

            //Set AutoGenerateColumns False
            dgArticles.AutoGenerateColumns = false;

            //Set Columns Count
            dgArticles.ColumnCount = 7;

            //Add Columns
            dgArticles.Columns[0].Name             = "Id";
            dgArticles.Columns[0].HeaderText       = "Id";
            dgArticles.Columns[0].DataPropertyName = "Id";
            dgArticles.Columns[0].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;

            dgArticles.Columns[1].HeaderText       = "Name";
            dgArticles.Columns[1].Name             = "Name";
            dgArticles.Columns[1].DataPropertyName = "Name";
            dgArticles.Columns[1].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;

            dgArticles.Columns[2].Name             = "Description";
            dgArticles.Columns[2].HeaderText       = "Description";
            dgArticles.Columns[2].DataPropertyName = "Description";
            dgArticles.Columns[2].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;


            dgArticles.Columns[3].Name             = "Price";
            dgArticles.Columns[3].HeaderText       = "Price";
            dgArticles.Columns[3].DataPropertyName = "Price";
            dgArticles.Columns[3].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;

            dgArticles.Columns[4].Name             = "TotalInShelf";
            dgArticles.Columns[4].HeaderText       = "TotalInShelf";
            dgArticles.Columns[4].DataPropertyName = "TotalInShelf";
            dgArticles.Columns[4].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;


            dgArticles.Columns[5].Name             = "TotalInVault";
            dgArticles.Columns[5].HeaderText       = "TotalInVault";
            dgArticles.Columns[5].DataPropertyName = "TotalInVault";
            dgArticles.Columns[5].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;



            dgArticles.Columns[6].Name             = "StoreId";
            dgArticles.Columns[6].HeaderText       = "StoreId";
            dgArticles.Columns[6].DataPropertyName = "StoreId";
            dgArticles.Columns[6].AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
            dgArticles.Columns[6].Visible          = false;

            dgArticles.DataSource = result.articles;
        }
コード例 #4
0
        // GET: Articles/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var response = await ArticlesServices.GetArticleAsync(id);

            if (response.success)
            {
                return(View(response.article));
            }
            else
            {
                ViewBag.ErrorMsg = "Ocurrió un error al tratar de obtener el artículo.";
                return(View("Error"));
            }
        }
コード例 #5
0
        /// <summary>
        /// Metodo para eliminar un registro
        /// </summary>
        private void Delete()
        {
            var articleDto = new ArticlesDto()
            {
                Id           = int.Parse(this.txtId.Text),
                Name         = this.txtName.Text,
                Description  = this.txtDescription.Text,
                Price        = decimal.Parse(this.txtPrice.Text),
                TotalInShelf = int.Parse(this.txtTotalInShelf.Text),
                TotalInVault = int.Parse(this.txtTotalInVault.Text),
                StoreId      = int.Parse(cbStore.SelectedValue.ToString())
            };
            ArticlesServices articleService = new ArticlesServices();

            articleService.Delete(articleDto);
            LoadGrid();
        }
コード例 #6
0
        // GET: Articles/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var response = await ArticlesServices.GetArticleAsync((int)id);

            if (response.success)
            {
                return(View(response.article));
            }
            else
            {
                return(View("Error"));
            }
        }
コード例 #7
0
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                var response = await ArticlesServices.DeleteArticlesAsync(id);

                if (response.success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
            catch
            {
                return(View());
            }
        }
コード例 #8
0
        public async Task <ActionResult> Edit(Articles_Create_VM vm)
        {
            try
            {
                vm.Article.Store = new Store {
                    id = vm.StoresSelectedID
                };
                var response = await ArticlesServices.PutArticlesAsync(vm.Article);

                if (response.success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
            catch
            {
                return(View());
            }
        }
コード例 #9
0
 public LikesController(LikesServices likes, ArticlesServices articles)
 {
     this.likes    = likes;
     this.articles = articles;
 }
コード例 #10
0
 public ArticlesController(ArticlesServices articles, CategoriesServices categories, TagsServices tags)
 {
     this.articles   = articles;
     this.categories = categories;
     this.tags       = tags;
 }
コード例 #11
0
 public ArticlesController(ArticlesServices articlesServices, MyDbContext context)
 {
     _articlesServices = articlesServices;
     _context          = context;
 }