Exemplo n.º 1
0
        public async Task <IActionResult> PutArticle(int id, 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());
        }
Exemplo n.º 2
0
        public void Add(T entity)
        {
            EntityEntry dbEntityEntry = context.Entry <T>(entity);

            context.Set <T>().Add(entity);

            context.SaveChanges();
        }
 public ActionResult Edit([Bind(Include = "ArticleID,AuthorID,Title,Content,Category,PublishDate,ArticleStatus,ArticleCover")] Article article)
 {
     //article.PublishDate = DateTime.Now;
     if (ModelState.IsValid)
     {
         article.ModifiedBy      = User.Identity.GetUserId();
         article.ModifiedOn      = DateTime.Now;
         db.Entry(article).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(article));
 }
Exemplo n.º 4
0
        public async Task <IActionResult> PutArticles([FromRoute] int id, [FromBody] Article article)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != article.ArticleId)
            {
                return(BadRequest());
            }

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

            try
            {
                _repo.Update(article);
                var save = await _repo.SaveAsync(article);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticlesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public ActionResult EditPost(Post editedPost)
        {
            db.Entry(editedPost).State = EntityState.Modified;
            int res = db.SaveChanges();

            return(Json(new { status = res }));
        }
Exemplo n.º 6
0
        public async Task Update_TestArticle_UpdatesTags()
        {
            AddTestArticleToDb();

            using (ArticleContext actContext = CreateDbContext())
            {
                ArticleRepository repo = new ArticleRepository(actContext);

                var testArticle = await repo.GetByIdAsync(1);

                testArticle.ReplaceTagIds(new [] { 3, 4 });
                await repo.UpdateAsync(testArticle);

                await actContext.SaveEntitiesAsync();
            }

            using (ArticleContext assertContext = CreateDbContext())
            {
                ArticleModel testModel = await assertContext.ArticleModels.FirstOrDefaultAsync();

                assertContext.Entry(testModel).Navigation("ArticleTags").Load();

                Assert.NotNull(testModel);

                Assert.Equal(new[] { 3, 4 }, testModel.ArticleTags.Select(at => at.TagId).OrderBy(i => i));
            }
        }
Exemplo n.º 7
0
        public void Update([FromBody] T entity)
        {
            context.Set <T>().Attach(entity);
            context.Entry(entity).State = EntityState.Modified;

            CleanCache(cacheKey);

            logger.LogInformation("Updated. " + JsonConvert.SerializeObject(entity));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Article")] Location location)
 {
     if (ModelState.IsValid)
     {
         db.Entry(location).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(location));
 }
Exemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "ID,Title,Content,CreatedDate, FirstName, LastName, CategoryName, Views")] Article article)
 {
     if (ModelState.IsValid)
     {
         db.Entry(article).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(article));
 }
Exemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "ID,Title,Date,Author,Content")] Article article)
 {
     if (ModelState.IsValid)
     {
         db.Entry(article).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(article));
 }
Exemplo n.º 11
0
 public ActionResult Edit([Bind(Include = "CategoryId,CategoryName")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
        public async Task <ActionResult <Article> > Put(string id, [FromBody] Article value)
        {
            if (id != value.id)
            {
                return(BadRequest("Ids dont match"));
            }
            context.Entry(value).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(Ok(value));
        }
Exemplo n.º 13
0
 public ActionResult ChangeArticle(Article article)
 {
     if (ModelState.IsValid)
     {
         using (ArticleContext db = new ArticleContext())
         {
             db.Entry(article).State = EntityState.Modified;
             db.SaveChanges();
         }
         return(RedirectToAction("Article", "Home"));
     }
     return(View(article));
 }
Exemplo n.º 14
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id != null)
            {
                Article article = new Article {
                    Id = id.Value
                };
                db.Entry(article).State = EntityState.Deleted;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(NotFound());
        }
Exemplo n.º 15
0
        public ActionResult Edit([Bind(Include = "Id,Name,ShortDescription,Description,Date")] Article article, int selectedCategory)
        {
            if (selectedCategory != null)
            {
                foreach (var c in db.Categories.Where(co => selectedCategory == co.CategoryId))
                {
                    article.Categories.Clear();
                    article.Categories.Add(c);
                }
            }
            article.Date = DateTime.Now;
            bool saveFailed;

            do
            {
                saveFailed = false;

                try
                {
                    if (ModelState.IsValid)
                    {
                        Article newArticle = new Article();
                        newArticle                  = (from a in db.Articles where a.Name == article.Name select a).Single();
                        newArticle.Description      = article.Description;
                        newArticle.Name             = article.Name;
                        newArticle.ShortDescription = article.ShortDescription;
                        newArticle.Categories.Clear();
                        newArticle.Categories      = article.Categories;
                        db.Entry(newArticle).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    //ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name"/* article.CategoryId*/);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;
                    Article newArticle = new Article();
                    newArticle        = (from a in db.Articles where a.Name == article.Name select a).Single();
                    article.ArticleId = newArticle.ArticleId;
                }
            } while (saveFailed);
            return(RedirectToAction("Index"));

            return(View(article));
        }
Exemplo n.º 16
0
 public void Update(Tag item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
 }
Exemplo n.º 17
0
 public ActionResult EditArticle(Article article)
 {
     db.Entry(article).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Admin"));
 }