Exemplo n.º 1
0
        public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] Article article)
        {
            if (id != article.Id)
            {
                return(BadRequest());
            }

            _context.Entry(article).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.Id)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <BrainStormUser> CreateUsersAsync(BrainStormUser brainStormUser)
        {
            brainStormUser.Id  = Guid.NewGuid();
            brainStormUser.URL = $@"{brainStormUser.UserName}_{brainStormUser.Id}";

            _context.Add(brainStormUser);
            await _context.SaveChangesAsync();

            return(brainStormUser);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id)
        {
            ArticleViewModel article = new ArticleViewModel()
            {
                Article  = await _unitService.Article.GetByIdAsync(id),
                Category = _unitService.Category.GetAll()
            };

            var articleCategory = await _unitService.ArticleCategory.getCategoryByArticleIdAsync(id);

            var catId   = articleCategory.First().CategoryId;
            var catName = await _unitService.Category.GetByIdAsync(catId);

            ViewBag.category = catName.Name;

            if (article.Article.Image == null)
            {
                article.Article.Image = "images/article/default_article.jpg";
                await _context.SaveChangesAsync();
            }
            if (article == null)
            {
                return(NotFound());
            }
            return(View(article));
        }