예제 #1
0
        public IActionResult Index()
        {
            var posts = _postsRepository.GetAll();
            var model = new GuestbookViewModel()
            {
                AllPosts = posts
            };

            return(View(model));
        }
예제 #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));
        }
예제 #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);
        }
예제 #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"));
 }
예제 #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);
        }