public ActionResult Return(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index"));
            }

            var model       = new BookViewModel();
            var bookBuilder = new BookModelBuilder();
            var modelList   = bookBuilder.CreateModelList(b => b.ISBN.StartsWith(id), 0, 1);

            if (modelList.Any())
            {
                model = modelList.FirstOrDefault();

                var userName = User.Identity.Name;

                var userBuilder = new LibraryUserModelBuilder();
                var userModel   = userBuilder.BuildModelFrom(userName);

                ViewBag.IsBookRentByMe = userModel.RentBooks != null && userModel.RentBooks.Where(r => r.ISBN.CompareTo(model.ISBN) == 0).Any();
            }
            else
            {
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <LibraryUserViewModel> CurrentLogonUserAsync()
        {
            var userName = User.Identity.Name;

            var userBuilder = new LibraryUserModelBuilder();
            var user        = await userBuilder.BuildModelFromAsync(userName);

            return(user);
        }
Exemple #3
0
        public async Task <ActionResult> Lock(int id)
        {
            if (id > 0)
            {
                var user = await UserManager.FindByIdAsync(id);

                if (user == null)
                {
                    return(HttpNotFound());
                }

                var userBuilder = new LibraryUserModelBuilder();
                var userModel   = await userBuilder.BuildModelFromAsync(user.UserName);

                ViewBag.HasUnreturnedBooks = userModel.RentBooks != null && userModel.RentBooks.Count > 0;

                return(View(user));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }