Exemple #1
0
        public ActionResult Edit([Bind(Include = "Id,Room,Place,IsTaken")] BookLocation bookLocation, string Readers)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }
            if (ModelState.IsValid)
            {
                bookLocation = db.BookLocations.Find(bookLocation.Id);
                var Reader = db.Readers.ToList().First(e => e.ToString() == Readers);
                db.Entry(bookLocation).State = EntityState.Modified;

                if (!db.BookLocations.Find(bookLocation.Id).IsTaken&& bookLocation.IsTaken)
                {
                    db.Stats.Add(new Stats {
                        DateTaken = DateTime.Now, Publication = bookLocation.Publication
                    });
                }
                db.BookLocations.Find(bookLocation.Id).Reader = Reader;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Publications = new SelectList(db.Publications, bookLocation.Publication);
            ViewBag.Readers      = new SelectList(db.Readers, bookLocation.Reader);

            return(View(bookLocation));
        }
Exemple #2
0
 /// <summary>
 /// GetLocationList
 /// </summary>
 /// <param name="location">model</param>
 /// <returns> return List Of page to display in grid </returns>
 public List <BookLocation> GetLocationList(BookLocation location)
 {
     using (ServiceContext service = new ServiceContext())
     {
         return(service.Search <BookLocation>(location, location.StartRowIndex, location.EndRowIndex, location.SortExpression, location.SortDirection).ToList());
     }
 }
Exemple #3
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string location = "";
            bool   isValid  = true;

            location = txtCreateLocation.Text.Trim();

            if (location.Length < 2)
            {
                isValid = false;
            }

            if (isValid)
            {
                BookLocation toCreate = new BookLocation()
                {
                    BookLocationPlace = location
                };

                if (LocationRepository.Instance.createLocationByLocation(toCreate))
                {
                    MessageBox.Show("Der Standort \"" + location + "\" wurder erfolgreich erfasst", "Abgeschlossen", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Der Standort existiert bereits", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                loadLocations();
            }
            txtCreateLocation.Clear();
        }
Exemple #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            {
                BookLocation bookLocation = db.BookLocations.Find(id);
                var          publications = db.Publications.Where(e => e.BookLocations.Any(f => f.Id == bookLocation.Id));
                foreach (Publication publication in publications)
                {
                    publication.BookLocations.Remove(bookLocation);
                }

                var readers = db.Readers.Where(e => e.BookLocations.Any(f => f.Id == bookLocation.Id));
                foreach (Reader reader in readers)
                {
                    reader.BookLocations.Remove(bookLocation);
                }

                db.BookLocations.Remove(bookLocation);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        public ActionResult Create([Bind(Include = "Id,Room,Place,IsTaken")] BookLocation bookLocation, string[] Publications, string[] Readers)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            if (Readers != null)
            {
                bookLocation.Reader = db.Readers.ToList().First(e => e.ToString() == Readers[0]);
            }
            bookLocation.Publication = db.Publications.ToList().First(e => Publications[0].Contains(e.ToString()));
            if (ModelState.IsValid)
            {
                db.BookLocations.Add(bookLocation);
                db.Stats.Add(new Stats {
                    DateTaken = DateTime.Now, Publication = bookLocation.Publication
                });
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Publications = new SelectList(db.Publications, bookLocation.Publication);
            ViewBag.Readers      = new SelectList(db.Readers, bookLocation.Reader);

            return(View(bookLocation));
        }
Exemple #6
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            string location = "";
            bool   isValid  = true;

            location = txtModifyLocation.Text.Trim();

            if (location.Length < 2)
            {
                isValid = false;
            }

            if (isValid)
            {
                BookLocation toUpdate = new BookLocation()
                {
                    BookLocationId    = selected.BookLocationId,
                    BookLocationPlace = location
                };

                if (LocationRepository.Instance.updateLocationByLocation(toUpdate))
                {
                    MessageBox.Show("Der Eintrag wurde erfolgreich geändert", "Abgeschlossen", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                loadLocations();
                txtModifyLocation.Clear();
            }
        }
Exemple #7
0
 public Task DisplayBook(BookData book, BookLocation location)
 {
     // The primary purpose of the DisplayBook to to turn off the help display!
     uiReaderControl.Visibility = Visibility.Visible;
     uiHelpControl.Visibility   = Visibility.Collapsed;
     return(Task.Delay(0));
 }
Exemple #8
0
        public JsonResult ChangeLocationStatus(int id = 0)
        {
            BookLocation model = new BookLocation();

            model.ID = id;
            if (id > 0)
            {
                model = this.masterDataBL.GetLocationList(model).FirstOrDefault();
            }

            if (model.Active == true)
            {
                model.Active = false;
            }
            else
            {
                model.Active = true;
            }

            int result = this.masterDataBL.SaveBookLocation(model);

            if (result > 0)
            {
                return(this.Json(new { success = true }));
            }
            else
            {
                return(this.Json(new { success = false, message = Messages.ErrorMessage.SetArguments(General.BookLocation) }));
            }
        }
Exemple #9
0
 public Book(long bookId, string title, string author, string isbn, BookType type, BookLocation location)
 {
     _bookId     = bookId;
     _bookTitle  = title;
     _author     = author;
     _isbn       = isbn;
     _type       = type;
     _location   = location;
     _checkedOut = false;
 }
        public bool deleteLocationByLocationId(int id)
        {
            BookLocation existing = context.BookLocations.FirstOrDefault(item => item.BookLocationId == id);

            if (existing == null)
            {
                return(false);
            }
            context.BookLocations.Remove(existing);
            context.SaveChanges();
            return(true);
        }
Exemple #11
0
        public JsonResult AddEditBookLocation(BookLocation bookLocation)
        {
            try
            {
                if (this.ModelState.IsValid)
                {
                    int    status         = this.masterDataBL.SaveBookLocation(bookLocation);
                    string message        = string.Empty;
                    string messageBoxType = Infrastructure.SystemEnumList.MessageBoxType.Success.GetDescription();
                    if (status > 0)
                    {
                        if (bookLocation.ID > 0)
                        {
                            message = Messages.UpdateMessage.SetArguments(General.BookLocation);
                        }
                        else
                        {
                            message = Messages.SaveMessage.SetArguments(General.BookLocation);
                        }
                    }
                    else
                    {
                        messageBoxType = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription();
                        message        = Messages.DuplicateMessage.SetArguments(General.BookLocation);
                    }

                    return(this.Json(new { resultData = status, status = messageBoxType, message = message, title = Infrastructure.SystemEnumList.Title.BookLocation.GetDescription(), JsonRequestBehavior.DenyGet }));
                }
                else
                {
                    string errorMsg = string.Empty;
                    foreach (ModelState modelState in this.ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            if (!string.IsNullOrEmpty(errorMsg))
                            {
                                errorMsg = errorMsg + " , ";
                            }

                            errorMsg = errorMsg + error.ErrorMessage;
                        }
                    }

                    return(this.Json(new { resultData = string.Empty, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = errorMsg, title = Infrastructure.SystemEnumList.Title.BookLocation.GetDescription(), JsonRequestBehavior.DenyGet }));
                }
            }
            catch (Exception ex)
            {
                return(this.Json(new { resultData = string.Empty, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = ex.Message == null ? ex.InnerException.Message : ex.Message, title = Infrastructure.SystemEnumList.Title.BookLocation.GetDescription(), JsonRequestBehavior.DenyGet }));
            }
        }
Exemple #12
0
        public bool createBook(Book book, Genre genre, List <Author> authors, BookLocation location)
        {
            bool result = true;

            Genre g = context.Genres.FirstOrDefault(x => x.GenreName == genre.GenreName);

            List <Author> a = new List <Author>();

            authors.ForEach(x => {
                a.Add(context.Authors.FirstOrDefault(y => y.AuthorName == x.AuthorName));
            });

            //context.Entry(a).State = EntityState.Unchanged;

            Book b = new Book()
            {
                BookName       = book.BookName,
                BookEdition    = book.BookEdition,
                BookISBN       = book.BookISBN,
                BookPagination = book.BookPagination,
                Authors        = a,
                Genre          = g
            };

            context.Books.Add(b);
            context.SaveChanges();

            int id = b.BookId;

            Book b2 = context.Books.FirstOrDefault(x => x.BookId == id);

            BookLocation bl = context.BookLocations.FirstOrDefault(x => x.BookLocationPlace == location.BookLocationPlace);

            if (b2 != null)
            {
                BookExemplar be = new BookExemplar()
                {
                    Book         = b2,
                    BookLocation = bl
                };

                context.BookExemplars.Add(be);
                context.SaveChanges();
            }
            else
            {
                result = false;
            }

            return(result);
        }
Exemple #13
0
        public ActionResult AddEditBookLocation(int id = 0)
        {
            BookLocation model = new BookLocation();

            model.ID = id;
            if (id > 0)
            {
                model = this.masterDataBL.GetLocationList(model).FirstOrDefault();
            }
            else
            {
                model.Active = true;
            }

            return(this.PartialView(PartialViews.AddEditBookLocation, model));
        }
        public ActionResult Create(BookLocation booklocation, HttpPostedFileBase file)
        {
            var sTitle = db.Book.Where(x => x.Title == booklocation.Book.Title);

            if (sTitle.Count() > 0)
            {
                var s = db.Book.Where(x => x.Title == booklocation.Book.Title).FirstOrDefault();;
                s.Amount          = booklocation.Book.Amount + s.Amount;
                db.Entry(s).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName);
                    booklocation.Book.ImagePath = file.FileName;
                }
                else
                {
                    booklocation.Book.ImagePath = null;
                }
                if (booklocation.Book.Amount > 0)
                {
                    booklocation.Book.Available = true;
                }
                else if (booklocation.Book.Amount < 0)
                {
                    ViewBag.err = "Amount can't be negative";
                    return(View("Error"));
                }
                else
                {
                    booklocation.Book.Available = false;
                }
                booklocation.Book.Book_ID = Guid.NewGuid();
                booklocation.Book.Loc_id  = booklocation.Location.Loc_ID;
                db.location.Add(booklocation.Location);
                db.Book.Add(booklocation.Book);
                db.SaveChanges();
                ViewBag.Pub_id = new SelectList(db.publisher, "Pub_Id", "Pub_Name", booklocation.Book.Pub_id);
                return(RedirectToAction("Index"));
            }
        }
Exemple #15
0
        /// <summary>
        /// Save Location
        /// </summary>
        /// <param name="location">Page</param>
        /// <returns>Id</returns>
        public int SaveBookLocation(BookLocation location)
        {
            using (ServiceContext service = new ServiceContext(false, "Name"))
            {
                if (location.ID > 0)
                {
                    location.ModifiedBy   = ProjectSession.UserId;
                    location.ModifiedDate = DateTime.Now;
                }
                else
                {
                    location.CreatedBy   = ProjectSession.UserId;
                    location.CreatedDate = DateTime.Now;
                }

                return(service.Save <BookLocation>(location));
            }
        }
Exemple #16
0
        private void listBoxLocation_SelectedValueChanged(object sender, EventArgs e)
        {
            var selection = listBoxLocation.SelectedItem;

            if (selection != null)
            {
                BookLocation l = locations.Find(item => item.BookLocationPlace == selection.ToString());

                if (l != null)
                {
                    selected = l;
                    txtModifyLocation.Text = l.BookLocationPlace;
                }
            }
            else if (listBoxLocation.Items.Count > 0)
            {
                listBoxLocation.SelectedIndex = 0;
            }
        }
        public bool createLocationByLocation(BookLocation bookLocation)
        {
            BookLocation existing = context.BookLocations.FirstOrDefault(item => item.BookLocationPlace.ToUpper() == bookLocation.BookLocationPlace.ToUpper());

            if (existing != null)
            {
                return(false);
            }

            BookLocation toSave = new BookLocation()
            {
                BookLocationPlace = bookLocation.BookLocationPlace
            };

            context.BookLocations.Add(toSave);
            context.SaveChanges();

            return(true);
        }
        private void UpdateBookLocationDeltas()
        {
            // clear the list and the counts
            BookLocationDeltas.Clear();
            if (BooksRead.Count < 1)
            {
                return;
            }
            DateTime startDate = BooksRead[0].Date;

            // get all the dates a book has been read (after the first quarter)
            Dictionary <DateTime, DateTime> bookReadDates = GetBookReadDates(startDate);

            // then add the delta made up of the books up to that date
            foreach (DateTime date in bookReadDates.Keys.ToList())
            {
                BookLocationDelta delta = new BookLocationDelta(date, startDate);
                foreach (var book in BooksRead)
                {
                    if (book.Date <= date)
                    {
                        WorldCountry country = GetCountryForBook(book);
                        if (country != null)
                        {
                            BookLocation location =
                                new BookLocation()
                            {
                                Book = book, Latitude = country.Latitude, Longitude = country.Longitude
                            };

                            delta.BooksLocationsToDate.Add(location);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                //delta.UpdateTallies();
                BookLocationDeltas.Add(delta);
            }
        }
        public bool updateLocationByLocation(BookLocation location)
        {
            BookLocation existing = context.BookLocations.FirstOrDefault(item => item.BookLocationId == location.BookLocationId);

            if (existing == null)
            {
                return(false);
            }

            BookLocation modified = context.BookLocations.FirstOrDefault(item => item.BookLocationPlace.ToUpper() == location.BookLocationPlace.ToUpper());

            if (modified != null)
            {
                return(false);
            }

            existing.BookLocationPlace = location.BookLocationPlace;
            context.SaveChanges();

            return(true);
        }
Exemple #20
0
        public JsonResult BookLocation([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel, string searchData = "")
        {
            List <BookLocation> bookLocationList;
            BookLocation        model = new BookLocation()
            {
                Name           = searchData,
                StartRowIndex  = requestModel.Start + 1,
                EndRowIndex    = requestModel.Start + requestModel.Length,
                SortDirection  = requestModel.OrderDir,
                SortExpression = requestModel.Columns.ElementAt(requestModel.OrderColumn).Data
            };

            bookLocationList = this.masterDataBL.GetLocationList(model);
            int totalRecord    = 0;
            int filteredRecord = 0;

            if (bookLocationList != null && bookLocationList.Count > 0)
            {
                totalRecord    = bookLocationList.FirstOrDefault().TotalRecords;
                filteredRecord = bookLocationList.FirstOrDefault().TotalRecords;
            }

            return(this.Json(new DataTablesResponse(requestModel.Draw, bookLocationList, filteredRecord, totalRecord), JsonRequestBehavior.AllowGet));
        }
 public void Post([FromBody] BookLocation bookLocation)
 {
     _db.BookLocation.Add(bookLocation);
     _db.SaveChanges();
 }
 public void Put(int id, [FromBody] BookLocation bookLocation)
 {
     bookLocation.BookLocationId   = id;
     _db.Entry(bookLocation).State = EntityState.Modified;
     _db.SaveChanges();
 }
Exemple #23
0
        static void Main(string[] args)
        {
            int            n             = 10;
            SLS            librarySystem = new SLS(true, n);
            Random         rand          = new Random();
            List <Student> students      = librarySystem.GetAllStudents();
            List <Book>    books         = librarySystem._catalog.GetAllBooks();
            Librarian      librarian     = librarySystem._librarian;
            Student        s             = students.ElementAt(rand.Next(n));
            bool           quit          = false;
            String         isbn          = "";
            String         bookIdInput   = "";
            String         title         = "";
            String         author        = "";
            BookType       type          = BookType.art;
            BookLocation   location      = BookLocation.firstFloor;
            long           bookID        = 0;

            //bool checkedOut = false;

            while (!quit)
            {
                Console.WriteLine("****     Welcome to Da Library!!      ******");
                Console.WriteLine();
                Console.WriteLine("Student Mode or Librarian Mode?");
                Console.WriteLine("'1' for Student");
                Console.WriteLine("'2' for Librarian");


                try
                {
                    char key = Console.ReadKey().KeyChar;
                    switch (key)
                    {
                    case '1':

                        Book b;
                        bool loop = true;
                        while (loop)
                        {
                            Console.WriteLine("**************** Student Mode **********************");
                            s.PrintStudentInfo();
                            Console.WriteLine("Checking Out or Returning?");
                            Console.WriteLine("'1' for Checking Out");
                            Console.WriteLine("'2' for Returning");
                            key = Console.ReadKey().KeyChar;

                            switch (key)
                            {
                            case '1':
                                librarySystem._catalog.PrintBooks();
                                Console.Write("Type the isbn of the book you want to check out: ");
                                string input1 = Console.ReadLine();

                                b = books.Where(x => x.GetIsbn() == input1).FirstOrDefault();
                                s.CheckOutBook(new Book(b.GetBookId(), b.GetTitle(), b.GetAuthor(), b.GetIsbn(), b.GetType(), b.GetLocation()), librarySystem._catalog);
                                Console.WriteLine("Book with ISBN#: " + b.GetIsbn() + " Checked Out!");
                                Console.WriteLine();
                                break;

                            case '2':
                                s.PrintBooksCheckedOut();
                                Console.Write("Type the isbn of the book you want to return: ");
                                string input2 = Console.ReadLine();

                                b = s.GetBooksCheckedOut().Where(x => x.GetIsbn() == input2).FirstOrDefault();
                                s.ReturnBook(new Book(b.GetBookId(), b.GetTitle(), b.GetAuthor(), b.GetIsbn(), b.GetType(), b.GetLocation()), librarySystem._catalog);
                                Console.WriteLine("Book with ISBN#: " + b.GetIsbn() + " Returned!");
                                Console.WriteLine();
                                break;
                            }
                            Console.WriteLine("Continue in Student Mode?");
                            Console.WriteLine("1 for yes");
                            Console.WriteLine("2 for no");
                            char looper = Console.ReadKey().KeyChar;
                            if (looper == '2')
                            {
                                loop = false;
                            }
                        }
                        break;

                    case '2':

                        Console.WriteLine("**************** Librarian Mode **********************");
                        Console.WriteLine("Librarians Can Add Books to the Catalog");
                        Console.WriteLine();
                        librarySystem._librarian.PrintLibrarianInfo();
                        Console.WriteLine();
                        Console.WriteLine("Enter book info");
                        Console.Write("BookId: ");
                        bookIdInput = Console.ReadLine();
                        bookID      = long.Parse(bookIdInput);
                        Console.Write("ISBN #: ");
                        isbn = Console.ReadLine();
                        Console.Write("Title: ");
                        title = Console.ReadLine();
                        Console.Write("Author: ");
                        author = Console.ReadLine();
                        Console.WriteLine("Book Types are as Follows");
                        Console.WriteLine("Science = 1");
                        Console.WriteLine("Arts = 2");
                        Console.WriteLine("Maths = 3");
                        Console.WriteLine("History = 4");
                        Console.WriteLine("Education = 5");
                        Console.WriteLine();
                        Console.Write("Enter Book Type #: ");
                        key = Console.ReadKey().KeyChar;
                        Console.WriteLine();
                        switch (key)
                        {
                        case '1':
                            type = BookType.science;
                            break;

                        case '2':
                            type = BookType.art;
                            break;

                        case '3':
                            type = BookType.math;
                            break;

                        case '4':
                            type = BookType.history;
                            break;

                        case '5':
                            type = BookType.education;
                            break;
                        }

                        b = new Book(bookID, title, author, isbn, type, location);
                        librarySystem._catalog.AddABook(librarySystem._librarian, b);
                        Console.WriteLine(b.GetTitle() + " Successfully Added to the Catalog");
                        Console.WriteLine();

                        break;

                    default:
                        Console.WriteLine("Invalid Input");
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message.ToString());
                    Console.WriteLine("Press any key to continue: ");
                    Console.ReadKey();
                    Console.WriteLine();
                }
            }
        }