Ejemplo n.º 1
0
        public ActionResult Edit(AddNewsViewModel model, HttpPostedFileBase file)
        {
            var entity = model.ToNewsResult()
                         .Update(x =>
            {
                x.LastUpdatedBy = UserName;
                x.IsDeleted     = !model.IsDeleted;
                if (!string.IsNullOrEmpty(file?.FileName))
                {
                    x.UrlImage = file.FileName;
                }
            });

            var result = NewsRepository.Update(entity);

            if (result == SaveResult.SUCCESS)
            {
                EnsureFolderNews(model.Id);
                SaveFile(model.Id, file);
            }
            else
            {
                ViewBag.HasError = true;
            }

            var newsCategory = NewsCategoryRepository.GetAll().Select(x => x.ToDataViewModel());

            model.NewsCategory = newsCategory;

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Add(AddNewsViewModel model, HttpPostedFileBase file)
        {
            var entity = model.ToNewsResult()
                         .Update(x =>
            {
                x.CreatedBy = UserName;
                x.IsDeleted = !model.IsDeleted;
                x.UrlImage  = file.FileName;
            });

            var result = NewsRepository.Add(entity);

            if (result == SaveResult.SUCCESS)
            {
                SaveFile(entity.Id, file);

                return(RedirectToRoute(UrlLink.NEWS_EDIT, new { id = entity.Id }));
            }
            ViewBag.HasError = true;
            var newsCategory = NewsCategoryRepository.GetAll().Select(x => x.ToDataViewModel());

            model.NewsCategory = newsCategory;
            return(View());
        }