public IActionResult GetById(int id)
        {
            var guestbook = _guestbookRepository.GetById(id);
            var dto       = GuestbookDTO.FromGuestbook(guestbook);

            return(Ok(dto));
        }
Example #2
0
        public IActionResult Index()
        {
            InitializeData();

            var guestbook = _guestbookRepository.GetById(1);
            var viewModel = new HomePageViewModel();

            viewModel.GuestbookName = guestbook.Name;
            viewModel.PreviousEntries.AddRange(guestbook.Entries);

            return(View(viewModel));
        }
        public ActionResult Index()
        {
            var model = _guestbookRepository.GetById(1);

            ViewBag.Message = model.Name;

            return(View());
        }
Example #4
0
        public GuestbookDto FindById(int Id)
        {
            IGuestbook theGuestbook = mGuestbookRepository.GetById(Id);

            if (theGuestbook != null)
            {
                GuestbookDto theGuestbookDto = new GuestbookDto
                {
                    Name = theGuestbook.Name,
                    Id   = theGuestbook.Id
                };

                return(theGuestbookDto);
            }

            return(null);
        }
Example #5
0
        public ActionResult Index()
        {
            UtilidadesBLL util = new UtilidadesBLL(_logger);

            util.DoTask();

            var model = _guestbookRepository.GetById(1);

            ViewBag.Message = model.Name;

            return(View());
        }
        public IActionResult Index()
        {
            if (!_guestbookRepository.List().Any())
            {
                var newGuestbook = new Guestbook()
                {
                    Name = "My Guestbook"
                };
                newGuestbook.Entries.Add(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hi!", DateTimeCreated = DateTime.UtcNow.AddHours(-2)
                });
                _guestbookRepository.Add(newGuestbook);
            }

            var guestbook = _guestbookRepository.GetById(1);
            var viewModel = new HomePageViewModel();

            viewModel.GuestbookName = guestbook.Name;
            viewModel.PreviousEntries.AddRange(guestbook.Entries);

            return(View(viewModel));
        }
        public void Handle(EntryAddedEvent entryAddedEvent)
        {
            var guestbook = _guestbookRepository.GetById(entryAddedEvent.GuestbookId);

            //notify all previous entries if posted in last day
            var emailsToNotify = _guestbookRepository
                                 .ListEntries(new GuestbookNotificationPolicy(entryAddedEvent.EntryAdded.Id))
                                 .Select(e => e.EmailAddress);

            foreach (var emailAddress in emailsToNotify)
            {
                string messageBody = $"{entryAddedEvent.EntryAdded.EmailAddress} left a message {entryAddedEvent.EntryAdded.Message}";
                _messageSender.SendGuestbookNotificationEmail(emailAddress, messageBody);
            }
        }
Example #8
0
        public void Handle(EntryAddedEvent entryAddedEvent)
        {
            var guestbook          = _guestbookRepository.GetById(entryAddedEvent.GuestbookId);
            var notificationPolicy = new GuestbookNotificationPolicy(entryAddedEvent.Entry.Id);

            // send updates to previous entries made in the last day
            var emailsToNotify = _guestbookRepository.ListEntries(notificationPolicy)
                                 .Select(e => e.EmailAddress);

            foreach (var emailAddress in emailsToNotify)
            {
                string messageBody = $"{entryAddedEvent.Entry.EmailAddress} left a new message {entryAddedEvent.Entry.Message}.";
                _messageSender.SendGuestbookNotificationEmail(emailAddress, messageBody);
            }
        }
 public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
 {
     if (context.ActionArguments.ContainsKey("id"))
     {
         var id = context.ActionArguments["id"] as int?;
         if (id.HasValue)
         {
             if ((_guestbookRepository.GetById(id.Value)) == null)
             {
                 context.Result = new NotFoundObjectResult(id.Value);
                 return;
             }
         }
     }
     await next();
 }
Example #10
0
        public IActionResult GetById(int id)
        {
            var guestbook = _guestbookRepository.GetById(id);

            return(Ok(guestbook));
        }
Example #11
0
        static void Main(string[] args)
        {
            /*Console.WriteLine("Hello World!");
             * IEntity<int> theEntity = new Guestbook();
             * Console.WriteLine(theEntity.ToString());
             * //Console.WriteLine(theEntity.IsTransient().ToString());
             * Entity theOtherEntity = new Guestbook();
             *
             * Console.WriteLine(theOtherEntity.IsTransient().ToString());
             *
             * // #2 static factory
             * Entity theThirdEntity = Guestbook.CreateGuestbook("novia visitor book");
             * ////////////////////////
             * IGuestbook theBook = Guestbook.CreateGuestbook("visit book");
             *
             * IGuestbookEntry theFirstEntry = new GuestbookEntry();
             * IGuestbookEntry theSecondEntry = new GuestbookEntry();
             *
             * // --------------------------------
             * theBook.AddEntry(theFirstEntry);
             * theBook.AddEntry(theSecondEntry);
             *
             * // --------------------------------
             * ///*/

            ////////////////////////
            var serviceCollection = new ServiceCollection();

            var bootStrapper = new Startup();

            bootStrapper.ConfigureServices(serviceCollection);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            using (EfGuestbookDbContext theContext = serviceProvider.GetService <EfGuestbookDbContext>())
            {
                ////////////////////////
                // hard work
                // The transient objects
                IGuestbook guestbook = serviceProvider.GetService <IGuestbook>();
                guestbook.Name = "Novia";

                IGuestbookEntry guestbookEntry = null;

                //#1
                guestbookEntry = serviceProvider.GetService <IGuestbookEntry>();
                guestbook.AddEntry(guestbookEntry);

                //#2
                guestbookEntry         = serviceProvider.GetService <IGuestbookEntry>();
                guestbookEntry.Message = "Testing entry.";
                guestbook.AddEntry(guestbookEntry);


                // Add the transient object to a repository, which knows how to store
                IGuestbookRepository theBookRepository = serviceProvider.GetService <IGuestbookRepository>();
                theBookRepository.Add(guestbook);

                //-------
                IGuestbook theBook = theBookRepository.GetById(3);
                //IGuestbook theBook = theBookRepository.ListAll()
                //    .ToList() // tuns the sql
                //    .Where(theIteratorBook => theIteratorBook.Name == "Novia").FirstOrDefault();

                theBook.Name = "Novia2";

                theBookRepository.Update(theBook as Guestbook);

                //-------

                ////////////////////////

                // Commit to the database
                theContext.SaveChanges();
            }
        }