コード例 #1
0
 static void Main()
 {
     NewsContext newsContext = new NewsContext();
     Article article = new Article();
     article.Content = "New article";
     newsContext.Articles.Add(article);
     newsContext.SaveChanges();
 }
コード例 #2
0
        public Article Create(Article newArticle)
        {
            this.articles.Add(newArticle);

            this.articles.SaveChanges();

            return newArticle;
        }
コード例 #3
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void lvArticles_UpdateItem(int id)
        {
            Article updatedArticle = new Article();

            TryUpdateModel(updatedArticle);
            this.ArticlesServices.UpdateById(id, updatedArticle);

            this.Response.Redirect("~/ViewArticle.aspx?id=" + id);
        }
コード例 #4
0
        public Article UpdateById(int id, Article updatedArticle)
        {
            var articleToUpdate = this.articles.GetById(id);

            articleToUpdate.CategoryId = updatedArticle.CategoryId;
            articleToUpdate.Content = updatedArticle.Content;
            articleToUpdate.Title = updatedArticle.Title;

            this.articles.SaveChanges();

            return updatedArticle;
        }
コード例 #5
0
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/Article/Create
        /// </summary>
        public ActionResult Create()
        {
            var data = new EditViewModel();

            Breadcrumbs.Current.AddBreadcrumb(data.breadcrumbLevel, "Add Article");
            var record = new Models.Article();

            record.PageID = Request["PageID"].ToInt(null);
            // any default values can be set here or in partial class Article.InitDefaults()
            record.UpdateFromRequest();              // grab any defaults from querystring
            record.Author = UserSession.Person.FullName;
            data.Article  = record;
            return(View("ArticleEdit", data));
        }
コード例 #6
0
        public void lvArticles_InsertItem()
        {
            var newArticle = new Article()
            {
                AuthorId = User.Identity.GetUserId(),
                DateCreated = DateTime.UtcNow
            };
            TryUpdateModel(newArticle);

            if (ModelState.IsValid)
            {
                this.ArticlesServices.Create(newArticle);
            }
        }
コード例 #7
0
 private void Save(Models.Article record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.DateAdded = DateTime.Now;
     record.Save();
     // delete all keyword for this article and its related urls and documents.
     AutocompletePhrase.AddPhrase("Article", record.ID, record.MetaKeywords, true);
     // save subform or related checkboxes here eg record.Lines.Save();
     //ifsubform: record.example.Save();
     foreach (var articleDocument in record.ArticleDocuments)
     {
         BewebCore.ThirdParty.SearchTextExtractor.CheckAttachmentsForDocOrPDFText(articleDocument);
     }
     CheckLock(record);
     lockobj.UnLockTable(record.GetTableName(), record.ID);
     ArticleCache.Rebuild();
 }
コード例 #8
0
        public ActionResult ArticlesCreate([DataSourceRequest]DataSourceRequest request, ArticleEditModel article)
        {
            if (this.ModelState.IsValid)
            {
                var newArticle = new Article
                                     {
                                         CategoryId = int.Parse(article.Category),
                                         Content = article.Content,
                                         Excerpt = article.Excerpt,
                                         PrimaryImageUrl = article.PrimaryImageUrl,
                                         Title = article.Title
                                     };

                this.articles.Create(newArticle);
            }

            return this.Json(new[] { article }.ToDataSourceResult(request, this.ModelState));
        }
コード例 #9
0
        protected ActionResult ProcessForm(Models.Article record)
        {
            try {
                record.UpdateFromRequest();
                // read subform or related checkboxes here eg record.Lines.UpdateFromRequest();
                record.ArticleDocuments.UpdateFromRequestSubForm();
                record.ArticleURLs.UpdateFromRequestSubForm();
                Validate(record);
                if (ModelState.IsValid)
                {
                    Save(record, record.IsNewRecord);
                    record.ArticleDocuments.Save();
                    record.ArticleURLs.Save();
                    Web.InfoMessage += "Article " + record.GetName() + " saved.";
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("ArticleEdit", new EditViewModel()
                {
                    Article = record
                }));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.Article();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage += "Copy of Article " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
コード例 #10
0
        private static IStore GenerateProducts(int count)
        {
            IStore store = new Store();
            var generator = RandomGenerator.Instance;

            for (var i = 0; i < count; i++)
            {
                var article = new Article()
                {
                    Price = generator.GetRandomDoubleNumber(i, i + 2),
                    Barcode = generator.GetRandomString(10),
                    Title = generator.GetRandomString(5),
                    Vendor = generator.GetRandomString(6)
                };

                store.AddArticle(article);
            }

            return store;
        }
コード例 #11
0
 private void Validate(Models.Article record)
 {
     // add any code to check for validity
     //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever.");
 }
コード例 #12
0
 public void AddArticle(Article article)
 {
     this.articles[article.Price].Add(article);
 }