Exemplo n.º 1
0
        public ActionResult Articles_Destroy([DataSourceRequest]DataSourceRequest request, Article article)
        {
            if (ModelState.IsValid)
            {
                this.articles.Delete(article.Id);
                this.articles.SaveChanges();
            }

            return this.Json(new[] { article }.ToDataSourceResult(request, this.ModelState));
        }
Exemplo n.º 2
0
        public ActionResult Articles_Update([DataSourceRequest]DataSourceRequest request, Article article)
        {
            if (ModelState.IsValid)
            {
                var entity = this.articles.GetById(article.Id);
                entity.Title = article.Title;
                entity.Content = article.Content;
                entity.CreatedOn = article.CreatedOn;
                entity.ArticleImage = article.ArticleImage;

                this.articles.SaveChanges();
            }

            var articleToDisplay = this.articles.All().FirstOrDefault(x => x.Id == article.Id);

            return this.Json(new[] { article }.ToDataSourceResult(request, this.ModelState));
        }
Exemplo n.º 3
0
        public ActionResult Articles_Create([DataSourceRequest]DataSourceRequest request, Article article)
        {
            var newId = 0;
            if (ModelState.IsValid)
            {
                var entity = new Article
                {
                    Title = article.Title,
                    Content = article.Content,
                    CreatedOn = article.CreatedOn,
                    ArticleImage = article.ArticleImage,
                };

                this.articles.Add(entity);
                this.articles.SaveChanges();
                article.Id = entity.Id;
                newId = entity.Id;
            }

            var articleToDisplay = this.articles.All().FirstOrDefault(x => x.Id == newId);

            return this.Json(new[] { articleToDisplay }.ToDataSourceResult(request, this.ModelState));
        }