Exemplo n.º 1
0
        public async Task <IActionResult> Index([Bind("Id,Message,Name")] Models.GuestBook guestBook)
        {
            _context.Add(guestBook);
            await _context.SaveChangesAsync();

            return(View(await _context.GuestBook.ToListAsync()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the images passed to Gallery DS
        /// </summary>
        /// <param name="dogGalleryData">Array with DogGalleryResponses passed to save</param>
        /// <returns></returns>
        public async Task SaveGalleryImagesAsync(DogGalleryResponse[] dogGalleryData)
        {
            await CheckRecords();

            var galleryData = dogGalleryData
                              .Select(d => new Gallery
            {
                Id      = new Guid(),
                Url     = d.Url,
                Created = DateTime.Now
            });


            await _db.Gallery.AddRangeAsync(galleryData);

            await _db.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <Guid> AddAsync(NewCommentModel comment)
        {
            var entry = await _context.Comments.AddAsync(_mapper.Map <Comment>(comment));

            await _context.SaveChangesAsync();

            _logger.LogDebug("Added new comment. Id: {Id}", entry.Entity.Id);

            return(entry.Entity.Id);
        }
Exemplo n.º 4
0
        public async Task <ActionResult <GuestBookEntry> > PostGuestBookEntry(FormEntry formEntry)
        {
            var guestBookEntry = new GuestBookEntry
            {
                Name      = formEntry.Name,
                Message   = formEntry.Message,
                TimeStamp = DateTime.Now
            };

            _context.GuestBookEntries.Add(guestBookEntry);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGuestBookEntry", new { id = guestBookEntry.Id }, guestBookEntry));
        }
Exemplo n.º 5
0
        public async Task <Guest> Create(CreateGuestRequest newGuestRequest)
        {
            var guest = new Guest()
            {
                Id        = Guid.NewGuid(),
                FirstName = newGuestRequest.FirstName,
                LastName  = newGuestRequest.LastName,
                Created   = DateTime.Now.ToUniversalTime()
            };

            await _db.GuestBook.AddAsync(guest);

            await _db.SaveChangesAsync();

            return(guest);
        }
Exemplo n.º 6
0
        public async void Test1()
        {
            // Setup
            var dbName  = Guid.NewGuid().ToString();
            var options = new DbContextOptionsBuilder <GuestBookContext>()
                          .UseInMemoryDatabase(databaseName: dbName).Options;

            var expectedGuest = new Guest()
            {
                Id        = Guid.NewGuid(),
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString(),
                Created   = DateTime.Now
            };

            // Seed
            await using (var dbContext = new GuestBookContext(options))
            {
                await dbContext.GuestBook.AddAsync(expectedGuest);

                await dbContext.SaveChangesAsync();
            }

            // Verify if insert works
            await using (var dbContext = new GuestBookContext(options))
            {
                var actualGuest = await dbContext.GuestBook.SingleAsync(x => x.Id == expectedGuest.Id);

                // verify reference
                actualGuest.Should().NotBe(null);

                // verify properties
                actualGuest.Id.Should().Be(expectedGuest.Id);
                actualGuest.FirstName.Should().Be(expectedGuest.FirstName);
                actualGuest.LastName.Should().Be(expectedGuest.LastName);
                actualGuest.Created.Should().Be(expectedGuest.Created);
            }
        }