Esempio n. 1
0
 public ActionResult New(Comment _comment)
 {
     _comment.CreatedBy = Guid.Parse(User.Identity.GetUserId());
     _comment.UserId    = User.Identity.GetUserId();
     _comment.CreatedOn = _comment.ModifiedOn = DateTime.Now;
     _repository.Add(_comment);
     return(RedirectToAction("Show", "News", new { id = _comment.NewsId }));
 }
Esempio n. 2
0
        public ActionResult Save(NewsForm news)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", news));
            }

            if (news.ViewMode == Enums.ViewMode.Add)
            {
                // New News
                var newsModel = Mapper.Map <NewsForm, News>(news);

                if (User.IsInRole("Administrator") || User.IsInRole("Editor"))
                {
                    newsModel.Status = "Approved";
                }
                else
                {
                    newsModel.Status = "Pending";
                }

                newsModel.CreatedBy  = Guid.Parse(User.Identity.GetUserId());
                newsModel.CreatedOn  = DateTime.Now;
                newsModel.UserId     = newsModel.CreatedBy.ToString();
                newsModel.ModifiedOn = newsModel.CreatedOn;
                _repository.Add(newsModel);
            }
            else
            {
                // Update News
                var newsInDb = _repository.FindById(news.Id);

                // Copy from VM
                newsInDb.Title          = news.Title;
                newsInDb.Image          = news.Image;
                newsInDb.Content        = news.Content;
                newsInDb.NewsCategoryId = news.NewsCategoryId;
                newsInDb.UserId         = User.Identity.GetUserId();
                newsInDb.ModifiedOn     = DateTime.Now;

                _repository.SaveChanges();
            }

            return(RedirectToAction("Index", "News"));
        }
 private void CreateNewCategoryContext(NewsCategory category) => _repository.Add(category);