public bool Add(AuthorBLL item, out string serverSideError) { if (item.IsValid) { using (ProtoLibEntities context = new ProtoLibEntities()) { if (DatabaseDependantValidation(item, context, out serverSideError)) { Author newAuth = new Author(); //newAuth.BookDetailsSet = whoa... Okay, remember.. first authors are added, then new books and author specified there CrossLayerEntityConverter.AuthorBllToDal(context, item, newAuth); context.Authors.AddObject(newAuth); context.SaveChanges(); return true; } } return false; } else { serverSideError = "The Author object is invalid"; return false; } }
public bool Delete(int id) { using (ProtoLibEntities context = new ProtoLibEntities()) { var dalAuth = (from a in context.Authors where a.AuthorID == id select a).SingleOrDefault(); if (dalAuth != null) { //ALT: Handle author deletion in a better way //Delete this author's credit from all books var creditedBooks = from b in context.BookDetailsSet where b.Authors.Contains(dalAuth) select b; foreach (BookDetails book in creditedBooks) book.Authors.Remove(dalAuth); context.Authors.DeleteObject(dalAuth); context.SaveChanges(); return true; } } return false; }
public bool Add(LibraryBookBLL item, out string serverSideError) { if (item.IsValid) { using (ProtoLibEntities context = new ProtoLibEntities()) { if (DatabaseDependantValidation(item, context, out serverSideError)) { LibraryBook newLibBook = new LibraryBook(); CrossLayerEntityConverter.LibraryBookBllToDal(context, item, newLibBook); context.LibraryBooks.AddObject(newLibBook); context.SaveChanges(); return true; } } return false; } else { serverSideError = "The LibraryBook object is invalid"; return false; } }
public bool Add(BookDetailsBLL item, out string serverSideError) { //HACK: in manip bar impl, we try to insert a new book before working on it. Better approach possible. if (item.Description.Title == null) item.Description.Title = "New book"; if (item.IsValid) { using (ProtoLibEntities context = new ProtoLibEntities()) { if (DatabaseDependantValidation(item,context, out serverSideError)) { //Good to go. BookDetails newBook = new BookDetails(); newBook.BookDimensions = new BookDimensions(); CrossLayerEntityConverter.BookDetailsBllToDal(context, item, newBook); context.BookDetailsSet.AddObject(newBook); context.SaveChanges(); return true; } } return false; } else { //FIXME: return IDataErrorInfo validation serverSideError = "The BookDetails object is invalid"; return false; } }
public List<TransactionBLL> GetMemberTransactions(int memberID) { using (ProtoLibEntities context = new ProtoLibEntities()) { Member mem = (from m in context.Members where m.MemberID == memberID select m).SingleOrDefault(); if (mem != null) { List<TransactionBLL> retList = new List<TransactionBLL>(); foreach (Transaction t in mem.Transactions) { TransactionBLL tr = new TransactionBLL(); CrossLayerEntityConverter.TransactionDalToBll(context, tr, t); retList.Add(tr); } return retList; } } return null; }
public static void AuthorBllToDal(ProtoLibEntities context, AuthorBLL bllAuthor, Author dalAuthor) { dalAuthor.FirstName = bllAuthor.FirstName; dalAuthor.MiddleName = bllAuthor.MiddleName; dalAuthor.LastName = bllAuthor.LastName; dalAuthor.DateOfBirth = bllAuthor.DateOfBirth; dalAuthor.DateOfDeath = bllAuthor.DateOfDeath; dalAuthor.Nationality = bllAuthor.Nationality; //FIXME: copy image binary data to BLL object dalAuthor.AuthorImage = bllAuthor.AuthorImage; foreach (int bookID in bllAuthor.BookDetailsIDs) dalAuthor.BookDetailsSet.Add(context.BookDetailsSet.Single(b => b.BookDetailsID == bookID)); }
public static void AuthorDalToBll(ProtoLibEntities context, AuthorBLL bllAuthor, Author dalAuthor) { bllAuthor.ItemID = dalAuthor.AuthorID; bllAuthor.FirstName = dalAuthor.FirstName; bllAuthor.MiddleName = dalAuthor.MiddleName; bllAuthor.LastName = dalAuthor.LastName; bllAuthor.DateOfBirth = dalAuthor.DateOfBirth; bllAuthor.DateOfDeath = dalAuthor.DateOfDeath; bllAuthor.Nationality = dalAuthor.Nationality; bllAuthor.AuthorImage = dalAuthor.AuthorImage; foreach (BookDetails b in dalAuthor.BookDetailsSet) bllAuthor.BookDetailsIDs.Add(b.BookDetailsID); }
public LibraryBookBLL GetByID(int id) { using (ProtoLibEntities context = new ProtoLibEntities()) { LibraryBook libBook = (from lb in context.LibraryBooks where lb.BookID == id select lb).SingleOrDefault(); if (libBook != null) { LibraryBookBLL retLibBook = new LibraryBookBLL(); CrossLayerEntityConverter.LibraryBookDalToBll(context, retLibBook, libBook); return retLibBook; } } return null; }
public bool IssueBook(int libBookID, int memberID, out string serverSideError) { serverSideError = null; using (ProtoLibEntities context = new ProtoLibEntities()) { LibraryBook libBook = (from lb in context.LibraryBooks where lb.BookID == libBookID select lb).SingleOrDefault(); if (libBook != null) { Member mem = (from m in context.Members where m.MemberID == memberID select m).SingleOrDefault(); if (mem != null) { Transaction t = new Transaction(); t.LibraryBook = libBook; t.Member = mem; t.Fine = 0.0; t.CheckedOutOn = DateTime.Now; t.ReturnedOn = null; libBook.BookStatus = (from st in context.BookStatus1 where st.StatusID == 101 select st).Single(); context.Transactions.AddObject(t); context.SaveChanges(); return true; } else { serverSideError = string.Format("No member with ID {0} exists", memberID.ToString()); return false; } } else { serverSideError = string.Format("No library book with that ID {0} exists", libBookID.ToString()); return false; } } }
public StaffAccountBLL GetByID(int id) { StaffAccountBLL bllSA = null; using (ProtoLibEntities context = new ProtoLibEntities()) { StaffAccount dalSA = (from sa in context.StaffAccounts where sa.AccountID == id select sa).SingleOrDefault(); if (dalSA != null) { bllSA = new StaffAccountBLL(); CrossLayerEntityConverter.StaffAccountDalToBll(context, bllSA, dalSA); } } return bllSA; }
public bool Delete(int id) { using (ProtoLibEntities context = new ProtoLibEntities()) { StaffAccount dalSA = (from sa in context.StaffAccounts.Include("AccountPrefs") where sa.AccountID == id select sa).SingleOrDefault(); if (dalSA != null) { context.AccountPrefsSet.DeleteObject(dalSA.AccountPrefs); context.StaffAccounts.DeleteObject(dalSA); context.SaveChanges(); return true; } } return false; }
/// <summary> ///Doesn't support automatically adding NEW related entities... eg. authors, ///categories, etc. /// </summary> public static void BookDetailsBllToDal(ProtoLibEntities context, BookDetailsBLL bllBook, BookDetails dalBook) { dalBook.ISBN13 = bllBook.PublishInfo.ISBN13; dalBook.ISBN10 = bllBook.PublishInfo.ISBN10; dalBook.EditionNumber = bllBook.PublishInfo.EditionNumber; dalBook.EditionName = bllBook.PublishInfo.EditionName; dalBook.Printing = bllBook.PublishInfo.Printing; dalBook.DatePublished = bllBook.PublishInfo.DatePublished; dalBook.Title = bllBook.Description.Title; dalBook.TitleLong = bllBook.Description.TitleLong; dalBook.Summary = bllBook.Description.Summary; dalBook.Notes = bllBook.Description.Notes; dalBook.Language = bllBook.Description.Language; dalBook.AmazonLink = bllBook.Description.AmazonLink; dalBook.BookDimensions.Pages = bllBook.Dimensions.Pages; dalBook.BookDimensions.Height = bllBook.Dimensions.Height; dalBook.BookDimensions.Width = bllBook.Dimensions.Width; dalBook.BookDimensions.Thickness = bllBook.Dimensions.Thickness; dalBook.BookDimensions.Weight = bllBook.Dimensions.Weight; //HACK: Use LINQ intersects dalBook.Authors.Clear(); foreach (int authorID in bllBook.AuthorIDs) dalBook.Authors.Add(context.Authors.First(a => a.AuthorID == authorID)); dalBook.Categories.Clear(); foreach (int categoryID in bllBook.CategoryIDs) dalBook.Categories.Add(context.Categories.First(c => c.CategoryID == categoryID)); dalBook.Subjects.Clear(); foreach (int subjectID in bllBook.SubjectIDs) dalBook.Subjects.Add(context.Subjects.First(s => s.SubjectID == subjectID)); //dalBook.PublisherID = bllBook.PublishInfo.PublisherID; if (bllBook.PublishInfo.PublisherID != null) dalBook.Publisher = context.Publishers.First(p => p.PublisherID == (int)bllBook.PublishInfo.PublisherID); }
public bool Delete(int id) { using (ProtoLibEntities context = new ProtoLibEntities()) { var book = (from b in context.BookDetailsSet.Include("BookDimensions") where b.BookDetailsID == id select b).SingleOrDefault(); if (book != null) { context.BookDimensions.DeleteObject(book.BookDimensions); var libBooks = book.LibraryBooks.ToList(); foreach (var lb in libBooks) context.DeleteObject(lb); var cats = book.Categories.ToList(); foreach (var c in cats) c.BookDetailsSet.Remove(book); foreach (Subject s in book.Subjects) s.BookDetailsSet.Remove(book); Publisher p = book.Publisher; p.BookDetailsSet.Remove(book); var auths = book.Authors.ToList(); foreach (var a in auths) a.BookDetailsSet.Remove(book); context.BookDetailsSet.DeleteObject(book); context.SaveChanges(); return true; } } return false; }
public bool Add(StaffAccountBLL item, out string serverSideError) { serverSideError = null; if (item.IsValid) { using (ProtoLibEntities context = new ProtoLibEntities()) { if (DatabaseDependantValidation(item, context, out serverSideError)) { StaffAccount dalSA = new StaffAccount(); dalSA.AccountPrefs = new AccountPrefs(); CrossLayerEntityConverter.StaffAccountBllToDal(context, item, dalSA); context.StaffAccounts.AddObject(dalSA); context.SaveChanges(); return true; } } } return false; }
public bool Delete(int id) { using (ProtoLibEntities context = new ProtoLibEntities()) { var libBook = (from lb in context.LibraryBooks where lb.BookInfoID == id select lb).SingleOrDefault(); if (libBook != null) { //FIXME: Don't remove transaction history on deleting book var trans = libBook.Transactions.ToList(); foreach (var t in trans) context.Transactions.DeleteObject(t); context.LibraryBooks.DeleteObject(libBook); context.SaveChanges(); return true; } } return false; }
private bool DatabaseDependantValidation(LibraryBookBLL bllLibBook, ProtoLibEntities context, out string error, int idToExclude = 0) { error = null; return true; }
public bool Update(List<LibraryBookBLL> items, out string serverSideError) { bool failure = false; serverSideError = null; string error = ""; string temp = ""; int numUpdated = 0; using (ProtoLibEntities context = new ProtoLibEntities()) { foreach (LibraryBookBLL bllLibBook in items) { if (bllLibBook.IsValid) { if (DatabaseDependantValidation(bllLibBook, context, out temp, bllLibBook.ItemID)) { LibraryBook dalLibBook = (from lb in context.LibraryBooks where lb.BookID == bllLibBook.ItemID select lb).SingleOrDefault(); if (dalLibBook != null) { CrossLayerEntityConverter.LibraryBookBllToDal(context, bllLibBook, dalLibBook); } else { error += "\nNo item with ID " + bllLibBook.ItemID.ToString() + " exists."; failure = true; } } else { error += ("\n" + temp); failure = true; } } else { error += ("\nItem with ID: " +bllLibBook.ItemID.ToString() + " is in an invalid state."); failure = true; } } numUpdated = context.SaveChanges(); } if (failure) { serverSideError = "There were unsuccessful updates. " + numUpdated.ToString() + " items were updated.\n" + error; return false; } Debug.Assert(serverSideError == null); return true; }
public bool Update(LibraryBookBLL newItem, out string serverSideError) { if (newItem.IsValid) { using (ProtoLibEntities context = new ProtoLibEntities()) { if (DatabaseDependantValidation(newItem, context, out serverSideError, newItem.ItemID)) { LibraryBook dalLibBook = (from lb in context.LibraryBooks where lb.BookID == newItem.ItemID select lb).Single(); CrossLayerEntityConverter.LibraryBookBllToDal(context, newItem, dalLibBook); context.SaveChanges(); Debug.Assert(serverSideError == null); return true; } else return false; } } serverSideError = "Item is in an invalid state!"; return false; }
public List<LibraryBookBLL> GetSurroundingItems(int midItemID, int numItemsBeforeAndAfter) { List<LibraryBookBLL> retList = new List<LibraryBookBLL>(); using (ProtoLibEntities context = new ProtoLibEntities()) { LibraryBookBLL midItem = GetByID(midItemID); if (midItem != null) { retList.AddRange(GetPreviousItems(midItemID, numItemsBeforeAndAfter)); retList.Add(midItem); retList.AddRange(GetNextItems(midItemID, numItemsBeforeAndAfter)); } } return retList; }
public List<LibraryBookBLL> GetPreviousItems(int beforeItemID, int numItems) { List<LibraryBookBLL> retList = new List<LibraryBookBLL>(); using (ProtoLibEntities context = new ProtoLibEntities()) { var dalLibBooks = (from lb in context.LibraryBooks where lb.BookID < beforeItemID orderby lb.BookID descending select lb).Take(numItems); LibraryBookBLL bllLibBook = null; foreach (LibraryBook dalLibBook in dalLibBooks) { bllLibBook = new LibraryBookBLL(); CrossLayerEntityConverter.LibraryBookDalToBll(context, bllLibBook, dalLibBook); retList.Add(bllLibBook); } } retList.Reverse(); return retList; }
public static void StaffAccountBllToDal(ProtoLibEntities context, StaffAccountBLL bllSA, StaffAccount dalSA) { dalSA.UserName = bllSA.UserName; dalSA.Password = bllSA.Password; dalSA.ClearanceLevel = bllSA.ClearanceLevel; dalSA.Member = context.Members.SingleOrDefault(m => m.MemberID == bllSA.MemberID); dalSA.AccountPrefs.CacheSize = bllSA.Preferences.CacheSize; dalSA.AccountPrefs.SearchResultsPageSize = bllSA.Preferences.SearchResultsPageSize; dalSA.AccountPrefs.FullScreenMode = bllSA.Preferences.FullScreenMode; }
public static void LibraryBookBllToDal(ProtoLibEntities context, LibraryBookBLL bllLibBook, LibraryBook dalLibBook) { dalLibBook.Price = bllLibBook.Price; dalLibBook.ObtainedFrom = bllLibBook.ObtainedFrom; dalLibBook.BookDetails = (from book in context.BookDetailsSet where book.BookDetailsID == bllLibBook.BookDetailsId select book).SingleOrDefault(); dalLibBook.BookStatus = (from st in context.BookStatus1 where st.StatusID == (int)bllLibBook.Status select st).Single(); //TODO: Implement branch stuff dalLibBook.Branch = (from br in context.Branches where br.BranchID == 100 select br).First(); }
public static void BookDetailsDalToBll(ProtoLibEntities context, BookDetailsBLL bllBook, BookDetails dalBook) { bllBook.ItemID = dalBook.BookDetailsID; bllBook.PublishInfo.ISBN13 = dalBook.ISBN13; bllBook.PublishInfo.ISBN10 = dalBook.ISBN10; bllBook.PublishInfo.EditionNumber = dalBook.EditionNumber; bllBook.PublishInfo.EditionName = dalBook.EditionName; bllBook.PublishInfo.Printing = dalBook.Printing; bllBook.PublishInfo.DatePublished = dalBook.DatePublished; bllBook.Description.Title = dalBook.Title; bllBook.Description.TitleLong = dalBook.TitleLong; bllBook.Description.Summary = dalBook.Summary; bllBook.Description.Notes = dalBook.Notes; bllBook.Description.Language = dalBook.Language; bllBook.Description.AmazonLink = dalBook.AmazonLink; bllBook.Dimensions.Pages = dalBook.BookDimensions.Pages; bllBook.Dimensions.Height = dalBook.BookDimensions.Height; bllBook.Dimensions.Width = dalBook.BookDimensions.Width; bllBook.Dimensions.Thickness = dalBook.BookDimensions.Thickness; bllBook.Dimensions.Weight = dalBook.BookDimensions.Weight; bllBook.AuthorIDs.Clear(); foreach (Author a in dalBook.Authors) bllBook.AuthorIDs.Add(a.AuthorID); bllBook.CategoryIDs.Clear(); foreach (Category c in dalBook.Categories) bllBook.CategoryIDs.Add(c.CategoryID); bllBook.SubjectIDs.Clear(); foreach (Subject s in dalBook.Subjects) bllBook.SubjectIDs.Add(s.SubjectID); bllBook.PublishInfo.PublisherID = bllBook.PublishInfo.PublisherID; }
public static void LibraryBookDalToBll(ProtoLibEntities context, LibraryBookBLL bllLibBook, LibraryBook dalLibBook) { bllLibBook.ItemID = dalLibBook.BookID; bllLibBook.Price = dalLibBook.Price; bllLibBook.ObtainedFrom = dalLibBook.ObtainedFrom; bllLibBook.BookDetailsId = dalLibBook.BookInfoID; bllLibBook.Status = (BookStatusBLL)(dalLibBook.StatusID); }
public static void TransactionDalToBll(ProtoLibEntities context, TransactionBLL bllTrans, Transaction dalTrans) { bllTrans.ItemID = dalTrans.TransactionID; bllTrans.BookID = dalTrans.BookID; bllTrans.MemberID = dalTrans.MemberID; bllTrans.CheckedOutOn = dalTrans.CheckedOutOn; bllTrans.ReturnedOn = dalTrans.ReturnedOn; bllTrans.Fine = dalTrans.Fine; }
public static void TransactionBllToDal(ProtoLibEntities context, TransactionBLL bllTrans, Transaction dalTrans) { dalTrans.LibraryBook = (from lb in context.LibraryBooks where lb.BookID == bllTrans.BookID select lb).SingleOrDefault(); dalTrans.Member = (from mem in context.Members where mem.MemberID == bllTrans.MemberID select mem).SingleOrDefault(); dalTrans.CheckedOutOn = bllTrans.CheckedOutOn; dalTrans.ReturnedOn = bllTrans.ReturnedOn; dalTrans.Fine = bllTrans.Fine; }
public static void MemberBllToDal(ProtoLibEntities context, MemberBLL bllMember, Member dalMember) { dalMember.FirstName = bllMember.FirstName; dalMember.MiddleName = bllMember.MiddleName; dalMember.LastName = bllMember.LastName; dalMember.DateOfBirth = bllMember.DateOfBirth; dalMember.JoinDate = bllMember.JoinDate; dalMember.Gender = bllMember.Gender; //FIXME: copy image binary data to BLL object dalMember.Portrait = bllMember.Portrait; dalMember.Contact.AddLine1 = bllMember.Contact.AddressLine1; dalMember.Contact.AddLine2 = bllMember.Contact.AddressLine2; dalMember.Contact.AddLine3 = bllMember.Contact.AddressLine3; dalMember.Contact.Phone1 = bllMember.Contact.Phone1; dalMember.Contact.Phone2 = bllMember.Contact.Phone2; dalMember.Contact.Email = bllMember.Contact.Email; dalMember.Contact.Website = bllMember.Contact.Website; dalMember.Contact.Pin = bllMember.Contact.Pin; City city = (from c in context.Cities where c.City1 == bllMember.Contact.City select c).FirstOrDefault(); if (city == null) { dalMember.Contact.City = new City(); dalMember.Contact.City.City1 = bllMember.Contact.City; dalMember.Contact.City.StateOrProvince = bllMember.Contact.StateOrProvince; dalMember.Contact.City.Country = bllMember.Contact.Country; } else { dalMember.Contact.City = city; } }
public List<LibraryBookBLL> GetFirstItems(int numItems) { List<LibraryBookBLL> retList = new List<LibraryBookBLL>(); using (ProtoLibEntities context = new ProtoLibEntities()) { var dalLibBooks = (from lb in context.LibraryBooks orderby lb.BookID select lb).Take(numItems); LibraryBookBLL bllLibBook = null; foreach (LibraryBook dalLibBook in dalLibBooks) { bllLibBook = new LibraryBookBLL(); CrossLayerEntityConverter.LibraryBookDalToBll(context, bllLibBook, dalLibBook); retList.Add(bllLibBook); } } return retList; }
public static void StaffAccountDalToBll(ProtoLibEntities context, StaffAccountBLL bllSA, StaffAccount dalSA) { bllSA.ItemID = dalSA.AccountID; bllSA.UserName = dalSA.UserName; bllSA.Password = dalSA.Password; bllSA.ClearanceLevel = dalSA.ClearanceLevel; bllSA.MemberID = dalSA.MemberID; bllSA.Preferences.CacheSize = dalSA.AccountPrefs.CacheSize; bllSA.Preferences.SearchResultsPageSize = dalSA.AccountPrefs.SearchResultsPageSize; bllSA.Preferences.FullScreenMode = dalSA.AccountPrefs.FullScreenMode; }
public static void MemberDalToBll(ProtoLibEntities context, MemberBLL bllMember, Member dalMember) { bllMember.ItemID = dalMember.MemberID; bllMember.FirstName = dalMember.FirstName; bllMember.MiddleName = dalMember.MiddleName; bllMember.LastName = dalMember.LastName; bllMember.DateOfBirth = dalMember.DateOfBirth; bllMember.JoinDate = dalMember.JoinDate; bllMember.Gender = dalMember.Gender; //FIXME: copy image binary data to BLL object bllMember.Portrait = dalMember.Portrait; bllMember.Contact.AddressLine1 = dalMember.Contact.AddLine1; bllMember.Contact.AddressLine2 = dalMember.Contact.AddLine2; bllMember.Contact.AddressLine3 = dalMember.Contact.AddLine3; bllMember.Contact.Phone1 = dalMember.Contact.Phone1; bllMember.Contact.Phone2 = dalMember.Contact.Phone2; bllMember.Contact.Email = dalMember.Contact.Email; bllMember.Contact.Website = dalMember.Contact.Website; bllMember.Contact.Pin = dalMember.Contact.Pin; bllMember.Contact.City = dalMember.Contact.City.City1; bllMember.Contact.StateOrProvince = dalMember.Contact.City.StateOrProvince; bllMember.Contact.Country = dalMember.Contact.City.Country; }