Exemplo n.º 1
0
        public ActionResult EditNewsItem(int id, EditNewsItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Image != null)
                    {
                        Utilities.JPPDirectory.CheckAndCreateNewsDirectory(Server);
                        model.ImageFilePath = Utilities.JPPDirectory.CreateFilePath(JPPDirectory.ImageTypes.News);
                        Utilities.JPPImage.Save(Server, model.ImageFilePath, model.Image.InputStream, JPPConstants.Images.NewsImageMaxSize, 0, true);
                    }

                    UnitOfWork work = new UnitOfWork();
                    work.SystemRepository.AdminEditNewsItem(id, model);
                    return RedirectToAction("Index");
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Edit Failed to Save: " + e.Message);
                }
            }

            return View(model);
        }
Exemplo n.º 2
0
        internal void AdminEditNewsItem(int id, EditNewsItemViewModel model)
        {
            news newsItem = _dbContext.news.Find(id);

            if (model.Title != null)
                newsItem.title = model.Title;

            if (model.Body != null)
                newsItem.body = model.Body;

            if (model.ImageFilePath != null)
                newsItem.image = model.ImageFilePath;

            newsItem.active = model.Active;

            Save();
        }