Esempio n. 1
0
 public ActionResult Create(NewsModels news)
 {
     if (ModelState.IsValid)
     {
         SysUserModels userSession = (SysUserModels)Session["UserSession"];
         news.newsImageFile = Request.Files["newsImageFile"];
         NewNewsDAO newsDAO = new NewNewsDAO(this.mapper);
         if (newsDAO.CreateNews(news, userSession))
         {
             news.infoMessage = Resource.MsgSuccess;
             return RedirectToAction("Index", "News");
         }
         else
         {
             MstNewsTypeDAO newsTypeDAO = new MstNewsTypeDAO(this.mapper);
             news.newsTypeModelsList = newsTypeDAO.GetAll();
             news.errorMessage = Resource.MsgFailed;
             return View(news);
         }
     }
     else
     {
         MstNewsTypeDAO newsTypeDAO = new MstNewsTypeDAO(this.mapper);
         news.newsTypeModelsList = newsTypeDAO.GetAll();
         return View(news);
     }
 }
Esempio n. 2
0
 public ActionResult Create()
 {
     NewsModels news = new NewsModels();
     MstNewsTypeDAO newsTypeDAO = new MstNewsTypeDAO(this.mapper);
     news.newsTypeModelsList = newsTypeDAO.GetAll();
     return View(news);
 }
Esempio n. 3
0
        public bool CreateNews(NewsModels news, SysUserModels userSession)
        {
            if (news.newsImageFile != null && !StringUtils.IsEmpty(news.newsImageFile.FileName))
            {
                news.newsImageName = news.newsImageFile.FileName;
                news.newsImage = new byte[news.newsImageFile.InputStream.Length];
                long bytesRead = news.newsImageFile.InputStream.Read(news.newsImage, 0, (int)news.newsImageFile.InputStream.Length);
                news.newsImageFile.InputStream.Close();
            }
            news.newsCode = Utils.UtilsDAO.GenerateCode(Constants.CodePrefix.NewNews);
            news.postedBy = userSession.userCode;
            news.createdBy = userSession.userCode;
            news.updatedBy = userSession.userCode;
            news.newsStatus = Constants.Status.Active;
            news.newsType = Constants.Type.Public;
            news.newsContent = HttpUtility.HtmlDecode(news.newsContent);
            news.localeID = Constants.Language.Vietnamese;
            mapper.Insert("New.insertNews", news);

            // insert other languages
            NewsModels enNews = TranslateUtils.TranslateNews(news, Constants.Language.English);
            mapper.Insert("New.insertNews", enNews);

            NewsModels ruNews = TranslateUtils.TranslateNews(news, Constants.Language.Russian);
            mapper.Insert("New.insertNews", ruNews);

            NewsModels chNews = TranslateUtils.TranslateNews(news, Constants.Language.Chinese);
            mapper.Insert("New.insertNews", chNews);
            return true;
        }
Esempio n. 4
0
        public static NewsModels TranslateNews(NewsModels news, string language)
        {
            NewsModels result = (NewsModels) news.Clone();
            if (!language.Equals(Constants.Language.English)
                && !language.Equals(Constants.Language.Russian)
                && !language.Equals(Constants.Language.Chinese)
                )
            {
                return result;
            }
            result.localeID = language;
            if (news == null || language.Equals(Constants.Language.Vietnamese))
            {
                return result;
            }

            result.newsTitle = TranslateText(result.newsTitle, language);
            result.newsIntro = TranslateText(result.newsIntro, language);
            result.newsContent = TranslateNewsContent(result.newsContent, language);
            return result;
        }
Esempio n. 5
0
 public ActionResult Edit(NewsModels news)
 {
     // TODO: Add update logic here
     SysUserModels userSession = (SysUserModels)Session["UserSession"];
     NewNewsDAO newsDAO = new NewNewsDAO(this.mapper);
     newsDAO.updateNews(news, userSession);
     return RedirectToAction("Index");
 }
Esempio n. 6
0
        public void updateNews(NewsModels news, SysUserModels userSession)
        {
            if (news.newsImageFile != null && !StringUtils.IsEmpty(news.newsImageFile.FileName))
            {
                news.newsImageName = news.newsImageFile.FileName;
                news.newsImage = new byte[news.newsImageFile.InputStream.Length];
                long bytesRead = news.newsImageFile.InputStream.Read(news.newsImage, 0, (int)news.newsImageFile.InputStream.Length);
                news.newsImageFile.InputStream.Close();
            }

            news.postedBy = userSession.userCode;
            news.createdBy = userSession.userCode;
            news.updatedBy = userSession.userCode;
            news.newsStatus = Constants.Status.Active;
            news.newsType = Constants.Type.Public;
            news.newsContent = HttpUtility.HtmlDecode(news.newsContent);
            news.localeID = Constants.Language.Vietnamese;
            mapper.Update("New.updateNews", news);

            NewsModels oldNews = this.getNews(news.newsCode, Constants.Language.Vietnamese);
            // update other languages
            if (news.newsImageFile == null || StringUtils.IsEmpty(news.newsImageFile.FileName))
            {
                news.newsImageName = oldNews.newsImageName;
                news.newsImage = oldNews.newsImage;
            }
            news.postedDate = oldNews.postedDate;
            NewsModels enNews = TranslateUtils.TranslateNews(news, Constants.Language.English);
            if (this.getNews(enNews.newsCode, Constants.Language.English) != null)
            {
                mapper.Update("New.updateNews", enNews);
            }
            else
            {
                mapper.Insert("New.insertNews", enNews);
            }

            NewsModels ruNews = TranslateUtils.TranslateNews(news, Constants.Language.Russian);
            if (this.getNews(ruNews.newsCode, Constants.Language.Russian) != null)
            {
                mapper.Update("New.updateNews", ruNews);
            }
            else
            {
                mapper.Insert("New.insertNews", ruNews);
            }

            NewsModels chNews = TranslateUtils.TranslateNews(news, Constants.Language.Chinese);
            if (this.getNews(chNews.newsCode, Constants.Language.Chinese) != null)
            {
                mapper.Update("New.updateNews", chNews);
            }
            else
            {
                mapper.Insert("New.insertNews", chNews);
            }
        }