public GuestbookDto Add(string sName) { IGuestbook newBook = Guestbook.CreateGuestbook(sName); newBook = mGuestbookRepository.Add(newBook); // engine code with storage //Mapping domain object to ui object GuestbookDto newBookDto = new GuestbookDto { Name = newBook.Name, Id = newBook.Id }; return(newBookDto); }
public bool Modify(GuestbookDto theGuestbook) { IGuestbook theBookToModify = mGuestbookRepository.GetById(theGuestbook.Id); if (theBookToModify != null) { // Mapping all ui objects to domain objects theBookToModify.Name = theGuestbook.Name; // fill in the guestbookentry list! mGuestbookRepository.Update(theBookToModify); return(true); } return(false); }
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); }
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(); } }