Пример #1
0
 public ActionResult CreateNews(NewInfo info, FormCollection f)
 {
     if (Session["account"] is null)
     {
         return(RedirectToAction("Login", "Login"));
     }
     else
     {
         var              account   = Session["account"] as Account;
         var              listtopic = f["topicstring"].ToString().Split(new char[] { ',' });
         Newspaper        news      = new Newspaper();
         NewspaperService svn       = new NewspaperService();
         news.Active          = 0;
         news.PublicationDate = DateTime.Now;
         news.Journalist      = account.AccountName;
         news.Title           = info.Title;
         news.Image           = info.Image;
         news.Description     = info.Description;
         svn.AddNewspaper(news);
         var            result = svn.GetAll().Last();
         MappingService svm    = new MappingService();
         foreach (var item in listtopic)
         {
             svm.AddMapping(new Mapping {
                 NewsId = result.NewsId, TopicId = Int32.Parse(item)
             });
         }
         return(RedirectToAction("CreateNews"));
     }
 }
 public ActionResult UpdateNews(NewInfo info, FormCollection f)
 {
     if (Session["account"] is null)
     {
         return(RedirectToAction("Login", "Login"));
     }
     else
     {
         var              account   = Session["account"] as AccountLogin;
         var              listtopic = f["topicstring"].ToString().Split(new char[] { ',' });
         Newspaper        news      = new Newspaper();
         NewspaperService svn       = new NewspaperService();
         news.PublicationDate = DateTime.Now;
         news.Active          = 0;
         news.NewsId          = info.NewsId;
         news.Title           = info.Title;
         news.Image           = info.Image;
         news.Description     = info.Description;
         news.Journalist      = account.AccountName;
         svn.UpdateNewspaper(news);
         MappingService svm  = new MappingService();
         var            getm = svm.GetAll().Where(x => x.NewsId == news.NewsId);
         var            s    = getm.ToList().Count;
         foreach (var item in getm.ToList())
         {
             svm.DeleteMapping(item.MappingId);
         }
         foreach (var item in listtopic)
         {
             svm.AddMapping(new Mapping {
                 NewsId = info.NewsId, TopicId = Int32.Parse(item)
             });
         }
         return(RedirectToAction("UpdateNews"));
     }
 }