Beispiel #1
0
        private List <BookRentHistoryViewModel> BuildHistory(string ISBN)
        {
            var resultList = new List <BookRentHistoryViewModel>();

            var historyList = base.LibraryContext.BookRentHistories.Where(h => h.ISBN.CompareTo(ISBN) == 0);

            if (historyList.Any())
            {
                foreach (var history in historyList)
                {
                    var model = new BookRentHistoryViewModel
                    {
                        UserId     = history.UserId,
                        ISBN       = history.ISBN,
                        RentOn     = history.RentOn,
                        ReturnedOn = history.ReturnedOn
                    };

                    resultList.Add(model);
                }
            }

            foreach (var result in resultList)
            {
                result.UserName = GetUserName(result.UserId);
            }

            return(resultList);
        }
        public async Task <ActionResult> ReturnConfirmed(string id)
        {
            if (ModelState.IsValid)
            {
                var rentModel = new BookRentHistoryViewModel();
                rentModel.ISBN = id;
                //rentModel.RentOn = DateTime.Now;
                rentModel.ReturnedOn = DateTime.Now;
                rentModel.UserName   = User.Identity.Name;

                var  rentCommand = new RentCommand();
                bool result      = await rentCommand.ExecuteAsync(rentModel);

                if (!result)
                {
                    ModelState.AddModelError("", "");
                    return(View());
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }