public IActionResult Index() { var posts = _postsRepository.GetAll(); var model = new GuestbookViewModel() { AllPosts = posts }; return(View(model)); }
public IActionResult AddPost(PostDto post) { post.CreatedOn = DateTime.UtcNow; _postsRepository.Add(post); var posts = _postsRepository.GetAll(); var model = new GuestbookViewModel() { AllPosts = posts }; return(View("Index", model)); }
public List <GuestbookViewModel> TakeGuestbook(int?numGuests = null) { List <GuestbookViewModel> guestBooksVM = new List <GuestbookViewModel>(); try { GuestbookServices services = new GuestbookServices(); List <Guestbook> guestBooks = services.TakeGuestbooks(numGuests); if (guestBooks.Any()) { guestBooksVM = guestBooks.Select(x => GuestbookViewModel.GetViewModel(x)).ToList(); } } catch (Exception exc) { exc.WriteToLog(); } return(guestBooksVM); }
public ActionResult New(GuestbookViewModel model) { try { Services bl = new Services(); ServiceResult result = bl.InsertGuestbook(model); if (!result.Esito && result.Exception == null) { throw new Exception(result.Message); } else if (!result.Esito && result.Exception != null) { throw result.Exception; } } catch (Exception exc) { exc.WriteToLog(); return(RedirectToAction("ErrorPage", "Home", new { errMsg = exc.ToCompleteMessage() })); } return(RedirectToAction("Get", "Guestbook")); }
public ServiceResult InsertGuestbook(GuestbookViewModel guestbookVM) { ServiceResult result; bool esito = false; string message = "Errore imprevisto"; try { GuestbookServices services = new GuestbookServices(); esito = true; message = string.Empty; services.InsertGuestbook(guestbookVM.ToGuestbookEntity(DateTime.Now)); result = new ServiceResult(esito, message); } catch (Exception exc) { message = exc.Message; esito = false; result = new ServiceResult(esito, message, exc); exc.WriteToLog(); } return(result); }