Exemplo n.º 1
0
        public IActionResult Index()
        {
            var posts = _postsRepository.GetAll();
            var model = new GuestbookViewModel()
            {
                AllPosts = posts
            };

            return(View(model));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 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"));
 }
Exemplo n.º 5
0
        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);
        }