コード例 #1
0
        public Task RegisterNew(NewsViewModel _new)
        {
            _repository.AddNew(_new);

            //Sends the notification of a new added to client side
            return(Clients.All.SendAsync("UpdateFeed", "A news has been added", default));
        }
コード例 #2
0
        public ActionResult Save(NewsArticle newsArticle)
        {
            if (!ModelState.IsValid)
            {
                NewsFormViewModel newsFormView = new NewsFormViewModel
                {
                    NewsArticle    = newsArticle,
                    NewsCategories = _repository.GetNewsCategories()
                };

                return(View(ViewName.NewsAdmin_NewsForm, newsFormView));
            }

            if (newsArticle.Id == 0)
            {
                newsArticle.Author      = User.Identity.Name;
                newsArticle.PublishDate = DateTime.Now;

                _repository.AddNew(newsArticle);
            }
            else
            {
                _repository.Update(newsArticle);
            }

            return(RedirectToAction(ViewName.NewsAdmin_Index, ControllerName.NewsAdmin));
        }
コード例 #3
0
        public async Task <IActionResult> AddNews([FromBody] NewsViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(PartialView("_FormResult", new ResultViewModel()
                    {
                        Success = false,
                        Message = "The news couldn't be added"
                    }));
                }

                await _newsRepository.AddNew(model);

                return(PartialView("_FormResult", new ResultViewModel()
                {
                    Success = true,
                    Message = "The news has been added"
                }));
            }
            catch (Exception ex)
            {
                return(PartialView("_FormResult", new ResultViewModel()
                {
                    Success = false,
                    Message = "The news couldn't be added. Internal error"
                }));
            }
        }