CodeShare Starter Kit Updated for Umbraco v8

Posted by Paul Seal on Wednesday, March 06, 2019

Following on from the success of the CodeShare Starter Kit which was built for Umbraco v7, it is now available for Umbraco v8.

Not only has it been updated to work on v8, it has also had some minor alterations to make it run smoother and faster, such as using caching for the navigation and footer links, and using GetCropUrl for the images.

public static class BookRepository
{
private static BookAppContext _db = new BookAppContext();

public static List<Book> GetAll()
{
var books = _db.Books.ToList();
return books;
}

public static Book GetById(int Id)
{
var book = _db.Books.Find(Id);
return book;
}

public static int Add(Book book)
{
_db.Books.Add(book);
_db.SaveChanges();
return book.Id;
}

public static Book Update(Book updatedBook)
{
var book = _db.Books.Find(updatedBook.Id);
book.ISBN = updatedBook.ISBN;
book.Title = updatedBook.Title;
_db.Entry(book).State = System.Data.Entity.EntityState.Modified;
_db.SaveChanges();
return book;
}

public static bool Delete(int Id)
{
var book = _db.Books.Find(Id);
if (book != null)
{
_db.Books.Remove(book);
_db.SaveChanges();
return true;
}
else
return false;
}
}