Esempio n. 1
0
        internal bool UpdateNews(NewsModel model, HttpRequestBase request)
        {
            if (request.Files["NewsImage"].ContentLength > 0)
            {
                HttpPostedFileBase file = request.Files["NewsImage"];
                string filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/uploads/news/"), Path.GetFileName(file.FileName));
                file.SaveAs(filePath);
                model.NewsImage = string.Format("\\Content\\uploads\\news\\{0}", file.FileName);
                model.IsImageRemoved = false;
            }
            //IsImageRemoved is a hidden field has flag of whether image removed or not
            if (request.Files["NewsImage"].ContentLength == 0 && model.IsImageRemoved)
            {
                model.NewsImage = null;
            }

            if (!model.IsImageRemoved && request.Files["NewsImage"].ContentLength == 0)
            {
                model.NewsImage = newsRepo.GetNewsImage(model.Id);
            }

            model.News = HttpUtility.HtmlEncode(model.News);
            model.IsVisible = true;
            News news = NewsMapper.NewsModelToNews(model);
            bool isUpdated = newsRepo.Update(news);
            return isUpdated;
        }
Esempio n. 2
0
        public ActionResult Create(NewsModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            NewsModel addedModel = newsBLL.AddNews(model, Request);
            return RedirectToAction("Create", new { status = ActionStatus.Success });
        }
Esempio n. 3
0
        public ActionResult Modify(NewsModel model)
        {

            if (!ModelState.IsValid)
                return View(model);

            bool isUpdated = newsBLL.UpdateNews(model, Request);

            return RedirectToAction("Modify", new { status = ActionStatus.Success });

        }
Esempio n. 4
0
 public static News NewsModelToNews(NewsModel newsModel)
 {
     return new News
     {
         CreatedOn = newsModel.CreatedOn,
         Id = newsModel.Id,
         IsDeleted = newsModel.IsDeleted,
         IsVisible = newsModel.IsVisible,
         NewsImage = newsModel.NewsImage,
         NewsText = newsModel.News,
         Title = newsModel.Title
     };
 }
Esempio n. 5
0
        internal NewsModel AddNews(NewsModel model, HttpRequestBase request)
        {
            if (request.Files["NewsImage"].ContentLength > 0)
            {
                HttpPostedFileBase file = request.Files["NewsImage"];
                string filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/uploads/news/"), Path.GetFileName(file.FileName));
                file.SaveAs(filePath);
                model.NewsImage = string.Format("\\Content\\uploads\\news\\{0}", file.FileName);
            }

            model.News = HttpUtility.HtmlEncode(model.News);
            model.IsVisible = true;
            model.CreatedOn = DateTime.UtcNow;
            News news = NewsMapper.NewsModelToNews(model);
            News addedNews = newsRepo.Add(news);
            return NewsMapper.NewsToNewsModel(addedNews);
        }