public HomeViewModel Initialize() { var model = new HomeViewModel { Projects = new List<Project>(), Message = new Message() }; model.Projects = _projects.Load(0, 3); SetNews(model.Projects); return model; }
public ActionResult Send(HomeViewModel model) { SetData(model); if (!ModelState.IsValid) return RedirectToAction("Index"); _homeService.SendMessage(model); try { ModelState.Clear(); } catch (NotSupportedException notSupportedException) { return Json("Сообщение отправлено\n" + notSupportedException.Message); } return Json("Сообщение отправлено"); }
private void SetData(HomeViewModel model) { model.Message.AuthorId = User.Identity.GetUserId(); model.Message.Date = DateTime.Now; }
public void SendMessage(HomeViewModel model) { _message.Add(model.Message); }