Esempio n. 1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var database = new BlogDBContext())
            {
                var newsArticle = database.NewsArticles
                                  .Where(n => n.Id == id)
                                  .First();

                if (newsArticle == null)
                {
                    return(HttpNotFound());
                }

                var model = new NewsArticleViewModel();
                model.Id             = newsArticle.Id;
                model.Title          = newsArticle.Title;
                model.Content        = newsArticle.Content;
                model.Author         = newsArticle.Author;
                model.OriginalSource = newsArticle.OriginalSource;

                return(View(model));
            }
        }
Esempio n. 2
0
        //private static List<News> FindArticleLogo(List<News> news)
        //{
        //    foreach(News item in news)
        //    {
        //        string newsLogo = "";

        //        if (item.Logo == null)
        //        {
        //            item.Logo = "~/images/img-placeholder.png";
        //        }
        //        else
        //        {
        //            // waiting for asher...
        //        }
        //    }

        //}

        /// <summary>
        /// The News
        /// </summary>
        /// <param name="id">The id<see cref="int"/></param>
        /// <returns>The <see cref="ActionResult"/></returns>
        public ActionResult News(int id)
        {
            ViewBag.NavTag = "News";

            NewsArticleViewModel news = GetNewsArticle(id);

            return(View(news));
        }
 public async Task Put(NewsArticleViewModel model)
 {
     try
     {
         await NewsArticleService.Update(model.ToEntity());
     }
     catch {
         Response.StatusCode = StatusCodes.Status400BadRequest;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// The GetNewsArticle
        /// </summary>
        /// <param name="id">The id<see cref="int"/></param>
        /// <returns>The <see cref="NewsArticleViewModel"/></returns>
        private NewsArticleViewModel GetNewsArticle(int id)
        {
            string Procedure = "News By Id";
            NewsArticleViewModel newsArticle = new NewsArticleViewModel();

            SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MintContext"].ConnectionString);
            SqlCommand    Command    = new SqlCommand(Procedure, Connection);

            Command.CommandType = CommandType.StoredProcedure;

            Command.Parameters.AddWithValue("@NewsId", id);

            using (Connection)
            {
                Connection.Open();
                var reader = Command.ExecuteReader();

                while (reader.Read())
                {
                    newsArticle.Article = new News();

                    newsArticle.Article.NewsId      = (int)reader["NewsId"];
                    newsArticle.Article.Title       = reader["Title"].ToString();
                    newsArticle.Article.Description = reader["Description"].ToString();
                    newsArticle.Article.Article     = reader["Article"].ToString();
                    newsArticle.Article.PostedDate  = Convert.ToDateTime(reader["PostedDate"]);
                    try
                    {
                        newsArticle.ClubName = reader["Name"].ToString();
                    }
                    catch
                    {
                        newsArticle.ClubName = "Mid-State";
                    }
                    try
                    {
                        newsArticle.ClubLogo = (byte[])reader["Image"];
                    }
                    catch
                    {
                        newsArticle.ClubLogo = null;
                    }
                }

                Connection.Close();
            }

            return(newsArticle);
        }
Esempio n. 5
0
        //
        // GET: Home/NewsArticle/Id
        public async Task <ActionResult> NewsArticle(int id)
        {
            // Getting the news article form the database
            NewsArticle article = await NewsManager.FindByIdAsync(id);

            // Getting the article
            NewsArticleViewModel model = new NewsArticleViewModel
            {
                Title     = article.Title,
                TextArea  = article.LongText,
                Date      = article.Date,
                CreatedBy = article.CreatedBy.UserName
            };

            return(View(model));
        }
        public async Task <ActionResult <NewsArticleViewModel> > PostNewsArticle(NewsArticleViewModel newsArticleViewModel)
        {
            var newsArticle = new NewsArticle
            {
                AuthorName           = newsArticleViewModel.AuthorName,
                ArticleTitle         = newsArticleViewModel.ArticleTitle,
                ArticleContent       = newsArticleViewModel.ArticleContent,
                ArticlePicture       = newsArticleViewModel.ArticlePicture,
                ArticlePictureCredit = newsArticleViewModel.ArticlePictureCredit,
                DateTimeCreated      = DateTime.Now.ToString("hh:mm | dd-MM-yyyy"),
                TimeStampUploaded    = DateTime.Now
            };

            _context.NewsArticles.Add(newsArticle);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetNewsArticle), new { id = newsArticleViewModel.ID }, newsArticle.NewsArticleToViewModel(newsArticleViewModel.AuthorName)));
        }
Esempio n. 7
0
        private IEnumerable <NewsArticleViewModel> GetArticles()
        {
            NewsArticleViewModel article1 = new NewsArticleViewModel();

            article1.ArticleBodyText = "Sample article 1";
            article1.FullUrl         = "http://www.google.com/article1";
            article1.Headline        = "Sensational headline";
            article1.OriginalAuthor  = "Nick Painter";

            NewsArticleViewModel article2 = new NewsArticleViewModel();

            article2.OriginalAuthor  = "Nicholas Charles Painter";
            article2.FullUrl         = "http://www.google.com/article2";
            article2.ArticleBodyText = "sample article body 2";
            article2.Headline        = "not so sensational headline";

            List <NewsArticleViewModel> retVal = new List <NewsArticleViewModel>();

            retVal.Add(article1);
            retVal.Add(article2);
            return(retVal);
        }
Esempio n. 8
0
        public ActionResult Edit(NewsArticleViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var database = new BlogDBContext())
                {
                    var newsArticle = database.NewsArticles
                                      .FirstOrDefault(n => n.Id == model.Id);

                    newsArticle.Title          = model.Title;
                    newsArticle.Content        = model.Content;
                    newsArticle.Author         = model.Author;
                    newsArticle.OriginalSource = model.OriginalSource;

                    database.Entry(newsArticle).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("List"));
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> PutNewsArticle(int id, NewsArticleViewModel newsArticleViewModel)
        {
            if (id != newsArticleViewModel.ID)
            {
                return(BadRequest());
            }

            var newsArticle = await _context.NewsArticles.FindAsync(id);

            if (newsArticle == null)
            {
                return(NotFound());
            }

            newsArticle.ArticleTitle         = newsArticleViewModel.ArticleTitle;
            newsArticle.ArticleContent       = newsArticleViewModel.ArticleContent;
            newsArticle.ArticlePicture       = newsArticleViewModel.ArticlePicture;
            newsArticle.ArticlePictureCredit = newsArticleViewModel.ArticlePictureCredit;

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

            return(NoContent());
        }
 public async Task Post(NewsArticleViewModel model)
 {
     await NewsArticleService.Add(model.ToEntity());
 }