Example #1
0
        public ActionResult Create(Book book, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                var rep = new DataRepositories();
                string authors = form["AuthorsListBox"];
                var selectedValues = new List<int>();
                if(authors != null)
                    selectedValues = authors.Split(',').Select(i => int.Parse(i)).ToList();
                foreach (int id in selectedValues)
                {
                    var author = rep.Authors.GetSingle(id);
                    book.Authors.Add(author);
                }
                if (book.Quantity > 0)
                    book.InStorage = true;
                else
                    book.InStorage = false;
                rep.Books.Add(book);
                return RedirectToAction("Index");
            }

            ViewBag.PublishingHouseID = new SelectList(db.PublishingHouses, "PublishingHouseID", "Name", book.PublishingHouseID);
            ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "GenreName", book.GenreID);
            ViewBag.StorageID = new SelectList(db.Storages, "StorageID", "StorageName", book.StorageID);
            ViewBag.PublicationTypeID = new SelectList(db.PublicationTypes, "PublicationTypeID", "TypeName", book.PublicationTypeID);
            ViewBag.Authors = new MultiSelectList(db.Authors, "AuthorID", "LastName", book.Authors);
            return View(book);
        }
Example #2
0
 public ActionResult Create(Subscribe subscribe)
 {
     var rep = new DataRepositories();
     if (!rep.Books.GetAll().Any(b => b.BookID == subscribe.BookID))
     {
         ModelState.AddModelError(string.Empty, "Book ID is invalid");
     }
     else
     {
         if (!rep.Books.GetSingle(subscribe.BookID).InStorage)
              ModelState.AddModelError(string.Empty, "This book isn't in storage");
     }
     if (!rep.Subscribers.GetAll().Any(s => s.SubscriberID == subscribe.SubscriberID))
         ModelState.AddModelError(string.Empty, "Subscriber ID is invalid");
     if (ModelState.IsValid)
     {
         subscribe.LibrarianID = rep.Users.GetSingle(WebSecurity.CurrentUserId).Librarian.LibrarianID;
         subscribe.DeliveryDate = DateTime.Now;
         subscribe.Status = false;
         rep.Subscribes.Add(subscribe);
         var b = rep.Books.GetSingle(subscribe.BookID);
         if (b.Subscribes.Where(s=>!s.Status).Count() >= b.Quantity)
             b.InStorage = false;
         else
             b.InStorage = true;
         rep.Books.Update(b);
         return RedirectToAction("Index");
     }
     return View(subscribe);
 }
Example #3
0
 public ActionResult DeleteConfirmed(int id)
 {
     var rep = new DataRepositories();
     Book book = rep.Books.GetSingle(id);
     book.Authors.Clear();
     rep.Books.Update(book);
     rep.Books.Remove(book);
     return RedirectToAction("Index");
 }
Example #4
0
        public ActionResult Register(RegisterModel model)
        {
            var rep = new DataRepositories();
            var librarian = rep.Librarians.GetAll().Where(l=>l.LibrarianID == model.LibrarianID ).FirstOrDefault();
            if (librarian == null)
            {
                ModelState.AddModelError(string.Empty, "LibrarianID is not exists");
            }

            if (librarian.User != null)
            {
                ModelState.AddModelError(string.Empty, "This librarianID is assigned");
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { LibrarianID = model.LibrarianID }, false);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Example #5
0
        public ActionResult SelectSubscribe(int BookID)
        {
            var rep = new DataRepositories();
            IEnumerable<Subscribe> s = rep.Books.GetSingle(BookID).Subscribes.Where(i=>!i.Status);

            return View(s);
        }
Example #6
0
 public ActionResult ReturnBook(int Id = 0)
 {
     var rep = new DataRepositories();
     var s = rep.Subscribes.GetSingle(Id);
     s.Status = true;
     rep.Subscribes.Update(s);
     var b = rep.Books.GetSingle(s.BookID);
     b.InStorage = true;
     rep.Books.Update(b);
     return RedirectToAction("Index");
 }
Example #7
0
        public ActionResult EnterBookId(int BookID)
        {
            var rep = new DataRepositories();
            if (!rep.Books.GetAll().Any(b => b.BookID == BookID))
            {
                ModelState.AddModelError(string.Empty, "Book ID is invalid");
            }

            if (ModelState.IsValid)
            {
                return RedirectToAction("SelectSubscribe", new {BookID = BookID });
            }
            return View();
        }