From f002f73f4d29fb483b1458dc80aa59c0163a5b36 Mon Sep 17 00:00:00 2001 From: Emanuele De Rosa <85497974+OliverQueenArrowTheBest@users.noreply.github.com> Date: Sat, 22 Oct 2022 12:57:16 +0200 Subject: [PATCH] Fixed message book arrived --- NationalLibrary/Metodi/DataQueries.cs | 128 ++++++++++-------- .../Views/Home/userDashboard.cshtml | 2 +- 2 files changed, 70 insertions(+), 60 deletions(-) diff --git a/NationalLibrary/Metodi/DataQueries.cs b/NationalLibrary/Metodi/DataQueries.cs index 3f75057..565e0f3 100644 --- a/NationalLibrary/Metodi/DataQueries.cs +++ b/NationalLibrary/Metodi/DataQueries.cs @@ -12,9 +12,9 @@ namespace NationalLibrary.Metodi { public class DataQueries { - - ////////////////// QUERY MANIPOLAZIONE UTENTI \\\\\\\\\\\\\\\\\\\\\ - public static void InsertUser(string FiscalCode, string Type, string Name, string Surname, string MobilePhone, DateTime BirthDate, string City, string Street, int? CAP, string Province, string DocumentNumber, string DocumentType, string ReleasedBy, DateTime ExpireOn, string Email, string Username, string Password, string FCRelatedTO, LibraryContext ctx) + + ////////////////// QUERY MANIPOLAZIONE UTENTI \\\\\\\\\\\\\\\\\\\\\ + public static void InsertUser(string FiscalCode, string Type, string Name, string Surname, string MobilePhone, DateTime BirthDate, string City, string Street, int? CAP, string Province, string DocumentNumber, string DocumentType, string ReleasedBy, DateTime ExpireOn, string Email, string Username, string Password, string FCRelatedTO, LibraryContext ctx) { // ctx = new LibraryContext(); var newuser = new Person() { FiscalCode = FiscalCode, Name = Name, Surname = Surname, Type = Type, MobilePhone = MobilePhone, BirthDate = BirthDate, FCRelatedTO = FCRelatedTO, SignUpDate = DateTime.Now }; @@ -66,7 +66,7 @@ public static void EditUser(string FiscalCode, string Type, string Name, string a.FiscalCode = FiscalCode; a.Type = Type; - + a.Name = Name; a.Surname = Surname; a.MobilePhone = MobilePhone; @@ -86,17 +86,17 @@ public static void EditUser(string FiscalCode, string Type, string Name, string ctx.SaveChanges(); } - public static bool CheckFCExsist(string FiscalCode, LibraryContext ctx) - { - bool check = false; + public static bool CheckFCExsist(string FiscalCode, LibraryContext ctx) + { + bool check = false; - Person a = ctx.People.Where(u => u.FiscalCode == FiscalCode).ToList()[0]; - if (a != null) { check = true; } + Person a = ctx.People.Where(u => u.FiscalCode == FiscalCode).ToList()[0]; + if (a != null) { check = true; } - return check; - } + return check; + } - public static UserFinalView getUserByFK (string FiscalCode, LibraryContext ctx) + public static UserFinalView getUserByFK(string FiscalCode, LibraryContext ctx) { UserFinalView user = ViewsLoaders.UserFinalViewList(ctx).Where(x => x.FiscalCode == FiscalCode).FirstOrDefault(); return user; @@ -119,8 +119,8 @@ public static void InsertBook(string Title, string Author, string PublishingHous ctx.Locations.Add(newbook.Location); ctx.SaveChanges(); } - else - { + else + { ctx.Books.Add(newbook); ctx.Locations.Add(newbook.Location); ctx.SaveChanges(); @@ -140,7 +140,7 @@ public static void DeleteBook(Guid BookGuid, LibraryContext ctx) ctx.SaveChanges(); } - public static void EditBook(Guid BookGuid, string Title, string Author, string PublishingHouse, bool Available, string Presentation, string Genre, byte[] Coverimg, string Room, string Scaffhold, string Shelf, int? Position, string ISBN,string Price, LibraryContext ctx) + public static void EditBook(Guid BookGuid, string Title, string Author, string PublishingHouse, bool Available, string Presentation, string Genre, byte[] Coverimg, string Room, string Scaffhold, string Shelf, int? Position, string ISBN, string Price, LibraryContext ctx) { Book a = ctx.Books.Where(u => u.BookGuid == BookGuid).ToList()[0]; @@ -180,9 +180,9 @@ public static void EditBook(Guid BookGuid, string Title, string Author, string P a.ISBNFK = ISBN; - ctx.SaveChanges(); + ctx.SaveChanges(); - if (!ISBNLeft(oldisbn, ctx)) + if (!ISBNLeft(oldisbn, ctx)) { if (w.Count > 0) { @@ -250,20 +250,20 @@ public static int CountBookAvaiable(string ISBN, LibraryContext ctx) public static bool ISBNLeft(string ISBN, LibraryContext ctx) { bool check = false; - if (CheckISBNExsist(ISBN, ctx)) - { + if (CheckISBNExsist(ISBN, ctx)) + { - ISBNList i = ctx.ISBNLists.Where(u => u.ISBN == ISBN).ToList()[0]; - List b = ctx.Books.Where(u => u.ISBNFK == i.ISBN).ToList(); - - if (b.Count > 0) { check = true; } - } + ISBNList i = ctx.ISBNLists.Where(u => u.ISBN == ISBN).ToList()[0]; + List b = ctx.Books.Where(u => u.ISBNFK == i.ISBN).ToList(); - // false = L'ISBN è presente in lista ma non ci sono libri associati - // true = L'ISBN è presente in lista ma ci sono ancora libri associati + if (b.Count > 0) { check = true; } + } + // false = L'ISBN è presente in lista ma non ci sono libri associati + // true = L'ISBN è presente in lista ma ci sono ancora libri associati - return check; + + return check; } public static void TryISBNDelete(string ISBN, LibraryContext ctx) @@ -281,10 +281,10 @@ public static void TryISBNDelete(string ISBN, LibraryContext ctx) } public static void EditISBNFromISBNList(string ISBN, LibraryContext ctx) { - ISBNList a = ctx.ISBNLists.Where(u => u.ISBN == ISBN).ToList()[0]; + ISBNList a = ctx.ISBNLists.Where(u => u.ISBN == ISBN).ToList()[0]; a.ISBN = ISBN; ctx.SaveChanges(); - } + } public static BookFinalView getBookByGuid(Guid BookGuid, LibraryContext ctx) { BookFinalView book = new BookFinalView(); @@ -303,10 +303,10 @@ public static BookFinalView BookWaitingbyCFISBN(string ISBN, string FiscalCode, List lista = new List(); - List b = ctx.WaitingLists.Where(u => u.FiscalCodeFK == FiscalCode && u.ISBNFK == ISBN).ToList(); - ISBNList i = ctx.ISBNLists.Where(u => u.ISBN == b[0].ISBNFK).ToList()[0]; - Book o = ctx.Books.Where(u => u.ISBNFK == i.ISBN).ToList()[0]; - Location l = ctx.Locations.Where(u => u.LocationGuid == o.LocationGuidFK).ToList()[0]; + List b = ctx.WaitingLists.Where(u => u.FiscalCodeFK == FiscalCode && u.ISBNFK == ISBN).ToList(); + ISBNList i = ctx.ISBNLists.Where(u => u.ISBN == b[0].ISBNFK).ToList()[0]; + Book o = ctx.Books.Where(u => u.ISBNFK == i.ISBN).ToList()[0]; + Location l = ctx.Locations.Where(u => u.LocationGuid == o.LocationGuidFK).ToList()[0]; BookFinalView pippo = new BookFinalView() { @@ -325,10 +325,10 @@ public static BookFinalView BookWaitingbyCFISBN(string ISBN, string FiscalCode, Scaffhold = l.Schaffold, Position = l.Position, Shelf = l.Shelf, - ISBN = o.ISBNFK + ISBN = o.ISBNFK - }; + }; return pippo; @@ -340,14 +340,14 @@ public static BookFinalView BookWaitingbyCFISBN(string ISBN, string FiscalCode, - } + } public static List SelectAllFromWL(LibraryContext ctx) { var wlview = from x in ctx.WaitingLists select x; - return wlview.ToList(); - } + return wlview.ToList(); + } ////////////////// QUERY MANIPOLAZIONE AFFITTI \\\\\\\\\\\\\\\\\\\\\\ public static void InsertRent(Guid BookGuid, string FiscalCode, LibraryContext ctx) @@ -361,15 +361,15 @@ public static void InsertRent(Guid BookGuid, string FiscalCode, LibraryContext c a.Available = false; ctx.SaveChanges(); } - public static void BookDeliveredFromRent(Guid BookGuid, LibraryContext ctx) - { - Rent a = ctx.Rents.Where(u => u.BookGuidFK == BookGuid).ToList()[0]; + public static void BookDeliveredFromRent(Guid BookGuid, LibraryContext ctx) + { + Rent a = ctx.Rents.Where(u => u.BookGuidFK == BookGuid).ToList()[0]; - a.WithdrawnOn = DateTime.Now; + a.WithdrawnOn = DateTime.Now; ctx.SaveChanges(); - } - public static void ReturnRent(Guid RentGuid, LibraryContext ctx) + } + public static void ReturnRent(Guid RentGuid, LibraryContext ctx) { Rent a = ctx.Rents.Where(u => u.RentGuid == RentGuid).ToList()[0]; @@ -415,15 +415,15 @@ public static void UpdateRequestState(Guid RequestGuid, string StateUpdate, stri } } - public static void UpdateRequestStateReject(Guid RequestGuid, string StateUpdate, LibraryContext ctx) - { - Request a = ctx.Requests.Where(u => u.RequestGuid == RequestGuid).ToList()[0]; - a.State = StateUpdate; - ctx.SaveChanges(); - } + public static void UpdateRequestStateReject(Guid RequestGuid, string StateUpdate, LibraryContext ctx) + { + Request a = ctx.Requests.Where(u => u.RequestGuid == RequestGuid).ToList()[0]; + a.State = StateUpdate; + ctx.SaveChanges(); + } - ////////////////// QUERY MANIPOLAZIONE ATTESE \\\\\\\\\\\\\\\\\\\\\\ - public static void InsertWaiting(string FiscalCode, string ISBN, bool IsFromRequest, LibraryContext ctx) + ////////////////// QUERY MANIPOLAZIONE ATTESE \\\\\\\\\\\\\\\\\\\\\\ + public static void InsertWaiting(string FiscalCode, string ISBN, bool IsFromRequest, LibraryContext ctx) { var newwaiting = new WaitingList() { WaitingGuid = Guid.NewGuid(), FiscalCodeFK = FiscalCode, RequestedOn = DateTime.Now, ISBNFK = ISBN, IsFromRequest = IsFromRequest }; ctx.WaitingLists.Add(newwaiting); @@ -447,15 +447,14 @@ public static void BookDeliveredFromWaiting(Guid WaitingGuid, LibraryContext ctx } - //////////////// QUERY AVVISI UTENTE \\\\\\\\\\\\\\\\\\\\\\ - public static List CheckIfBookArrived(string FiscalCode, LibraryContext ctx) + //////////////// QUERY AVVISI UTENTE \\\\\\\\\\\\\\\\\\\\\\ + public static List CheckIfBookArrived(string FiscalCode, LibraryContext ctx) { List lista = new List(); Person p = ctx.People.Where(u => u.FiscalCode == FiscalCode).ToList()[0]; List w = ctx.WaitingLists.Where(u => u.FiscalCodeFK == p.FiscalCode).ToList(); - //Rent r = ctx.Rents.Where(u => u.FiscalCodeFK == FiscalCode).ToList()[0]; @@ -467,17 +466,28 @@ public static List CheckIfBookArrived(string FiscalC List b = ctx.Books.Where(u => u.ISBNFK == l.ISBN).ToList(); foreach (var item in b) { - if (item.Available) + var r = from a in ctx.Rents + where a.FiscalCodeFK == FiscalCode + join book in ctx.Books on a.BookGuidFK equals book.BookGuid + select new Rent + { + BookGuidFK = book.BookGuid, + WithdrawnOn = a.WithdrawnOn + }; + foreach (var i in r) { + if (w[e].ReceivedOn != null && i.WithdrawnOn.Year == 1 && i.BookGuidFK == item.BookGuid) + { - string Title = item.Title; - lista.Add(new WaitingBookStatusFinalView(Name, Title)); + string Title = item.Title; + lista.Add(new WaitingBookStatusFinalView(Name, Title)); + } } } } - return lista; + return lista; } diff --git a/NationalLibrary/Views/Home/userDashboard.cshtml b/NationalLibrary/Views/Home/userDashboard.cshtml index 8769222..11debc4 100644 --- a/NationalLibrary/Views/Home/userDashboard.cshtml +++ b/NationalLibrary/Views/Home/userDashboard.cshtml @@ -226,7 +226,7 @@ { @:_books.push("@item.Title"); } - swal("Ciao @Model.Name i seguenti libri sono ora disponibili " + _books.join(", ")); + swal("Ciao @Model.Name i seguenti libri sono ora disponibili e da ritirare in biblioteca: " + _books.join(", ")); }