private static void UpdateNewsContent(News firstNews, NewsDbContext context)
 {
     Console.WriteLine("Text from DB: " + firstNews.Content);
     Console.Write("Enter the corrected text: ");
     string newContent = Console.ReadLine();
     firstNews.Content = newContent;
 }
Beispiel #2
0
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/News/PreLoad
        /// </summary>
        public ActionResult PreLoad(FormCollection collection)
        {
            Breadcrumbs.Current.AddBreadcrumb(3, "Add News from RSS");
            var record = new Models.News();
            // any default values can be set here or in partial class News.InitDefaults()

            string text = "";

            if ((text = Request["title"]).IsNotBlank())
            {
                record.IntroductionText = Server.UrlDecode(text);
            }
            if ((text = Request["feedname"]).IsNotBlank())
            {
                record.Source = Server.UrlDecode(text);
            }
            if ((text = Request["link"]).IsNotBlank())
            {
                record.LinkUrl = Server.UrlDecode(text);
            }
            if ((text = Request["description"]).IsNotBlank())
            {
                record.BodyTextHtml = Server.UrlDecode(text);
            }
            if ((text = Request["pubDate"]).IsNotBlank())
            {
                var dateText   = Server.UrlDecode(text);               //		Server.UrlDecode(text)	"Wed, 17 Aug 2011 21:54:44 EDT"	string
                var simpleDate = Rfc822DateTime.Parse(dateText);
                record.PublishDate = simpleDate;
            }

            return(View("NewsEdit", record));
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Application started.");
            using (var context = new NewsDb())
            {
                var news = context.News.ToList();
                var count = 1;
                news.ForEach(n =>
                {
                    Console.WriteLine("{0}. {1}", count, n.Content);
                    count++;
                });

                var continueReading = true;
                while (continueReading)
                {
                    Console.WriteLine("Enter news content:");
                    var content = Console.ReadLine();
                    var newNews = new News() { Content = content };
                    context.News.Add(newNews);

                    try
                    {
                        context.SaveChanges();
                        continueReading = false;
                        Console.WriteLine("Changes successfully saved in the DB.");
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        Console.WriteLine("Conflict! Text from DB: {0}", content);
                    }
                }
            }
        }
        public News AddNews(News toAdd)
        {
            toAdd.DateCreated = DateTime.UtcNow;
            this.news.Add(toAdd);
            this.news.SaveChanges();

            return toAdd;
        }
Beispiel #5
0
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/News/Create
        /// </summary>
        public ActionResult Create()
        {
            Breadcrumbs.Current.AddBreadcrumb(3, "Add News");
            var record = new Models.News();

            // any default values can be set here or in partial class News.InitDefaults()

            return(View("NewsEdit", record));
        }
Beispiel #6
0
        protected ActionResult ProcessForm(Models.News record)
        {
            try {
                record.UpdateFromRequest();
                // read subform or related checkboxes here eg record.Lines.UpdateFromRequest();
                Validate(record);
                if (ModelState.IsValid)
                {
                    Save(record, record.IsNewRecord);
                    Web.InfoMessage = "News " + record.GetName() + " saved.";
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("NewsEdit", record));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.News();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage = "Copy of News " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
 public void Update(News toUpdate)
 {
     this.news.Update(toUpdate);
     this.news.SaveChanges();
 }
Beispiel #8
0
 private void Save(Models.News record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.Save();
     // save subform or related checkboxes here eg record.Lines.Save();
 }
Beispiel #9
0
 private void Validate(Models.News record)
 {
     // add any code to check for validity
     //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever.");
 }
Beispiel #10
0
        public News Find(int id)
        {
            News newObj = new Models.News();

            return(newObj);
        }