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

            GoodNew selectedNews = db.GoodNews.Find(id);

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

            var           currentUser = UserManager.FindById(User.Identity.GetUserId());
            NewsViewModel news        = new NewsViewModel();

            ViewBag.IsUserAdmin = UserManager.IsInRole(User.Identity.GetUserId(), "Admin");
            news.Authors        = GetAuthorsFromDB();
            news.UserInfoId     = currentUser.UserInfo.Id;
            news.FirstName      = currentUser.UserInfo.FirstName;
            news.LastName       = currentUser.UserInfo.LastName;
            news.NewsTypes      = new Dictionary <string, string>
            {
                { "SchoolLife", "School Life" },
                { "BreakingNews", "Break News" },
                { "Entertainment", "Entertainment" },
                { "Sports", "Sports" }
            };
            news.NewsType = selectedNews.NewsType;
            news.Title    = selectedNews.Title;
            news.Content  = selectedNews.Content;
            news.Id       = selectedNews.Id;
            return(View(news));
        }
Esempio n. 2
0
        public ActionResult Create(NewsViewModel news, HttpPostedFileBase newsFile)
        {
            if (ModelState.IsValid)
            {
                if (newsFile != null)
                {
                    string path = Server.MapPath("~/Content/Uploads/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    newsFile.SaveAs(path + Path.GetFileName(newsFile.FileName));
                    news.FileName = newsFile.FileName;
                }

                GoodNew goodNew = new GoodNew
                {
                    Title      = news.Title,
                    Content    = news.Content,
                    NewsType   = news.NewsType,
                    NewsDate   = DateTime.Now,
                    FileName   = news.FileName,
                    UserInfoId = news.UserInfoId
                };
                db.GoodNews.Add(goodNew);
                db.SaveChanges();
                return(RedirectToAction("ManageNews"));
            }

            return(View(news));
        }
        bool IGoodnewsRepository.Delete(int id)
        {
            GoodNew GoodNew = GoodNewsDB.GoodNews.Find(id);

            GoodNewsDB.GoodNews.Remove(GoodNew);
            GoodNewsDB.SaveChanges();
            return(true);
        }
Esempio n. 4
0
        public ActionResult Delete(int id)
        {
            GoodNew news = db.GoodNews.Find(id);

            db.GoodNews.Remove(news);
            db.SaveChanges();
            return(RedirectToAction("ManageNews"));
        }
 GoodNew IGoodnewsRepository.Add(GoodNew item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     // TO DO : Code to save record into database
     GoodNewsDB.GoodNews.Add(item);
     GoodNewsDB.SaveChanges();
     return(item);
 }
 public IEnumerable <GoodNew> PutGoodnews(int id, GoodNew goodnew)
 {
     goodnew.NewsId = id;
     if (repo.Update(goodnew))
     {
         return(repo.GetAll());
     }
     else
     {
         return(null);
     }
 }
Esempio n. 7
0
 public ActionResult Edit(NewsViewModel news)
 {
     if (ModelState.IsValid)
     {
         GoodNew selectedNews = db.GoodNews.Where(x => x.Id == news.Id).SingleOrDefault();
         selectedNews.UserInfoId      = news.UserInfoId;
         selectedNews.Title           = news.Title;
         selectedNews.NewsType        = news.NewsType;
         selectedNews.Content         = news.Content;
         db.Entry(selectedNews).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("ManageNews"));
     }
     return(View(news));
 }
Esempio n. 8
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GoodNew selectednews = db.GoodNews.Find(id);

            if (selectednews == null)
            {
                return(HttpNotFound());
            }
            NewsViewModel news = new NewsViewModel();

            news.Id    = selectednews.Id;
            news.Title = selectednews.Title;
            return(View(news));
        }
        bool IGoodnewsRepository.Update(GoodNew item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to update record into database
            var Goodnew = GoodNewsDB.GoodNews.Single(a => a.NewsId == item.NewsId);

            Goodnew.Title        = item.Title;
            Goodnew.NewsDate     = item.NewsDate;
            Goodnew.JournalistId = item.JournalistId;
            Goodnew.Content      = item.Content;
            Goodnew.ImageUrl     = item.ImageUrl;
            Goodnew.NewsType     = item.NewsType;

            GoodNewsDB.SaveChanges();
            return(true);
        }
 public GoodNew PostGoodnews(GoodNew item)
 {
     return(repo.Add(item));
 }