public PartialViewResult Search(PassengerNumberSearchModel search) { search.Page = search.Page == 0 ? 1 : search.Page; ViewBag.Page = search.Page; ViewBag.PageSize = search.PageSize; ViewBag.Keyword = search.Keyword; decimal searchPrice = 0; decimal.TryParse(search.Keyword, out searchPrice); var passengerNumbers = _UnitOfWork.PassengerNumberRepository.All().Where(x => string.IsNullOrEmpty(search.Keyword) || (x.Name.ToLower().Contains(search.Keyword.ToLower()) || x.Value.ToString().Contains(search.Keyword))) .OrderByDescending(x => x.Value); ViewBag.ResultCount = passengerNumbers.Count(); int result = (passengerNumbers.Count() / search.PageSize) + (passengerNumbers.Count() % search.PageSize > 0 ? 1 : 0); if (search.Page > 1 && result < search.Page) { ViewBag.Page = search.Page - 1; return(PartialView(passengerNumbers.ToPagedList(search.Page - 1, search.PageSize))); } else { return(PartialView(passengerNumbers.ToPagedList(search.Page, search.PageSize))); } }
public ActionResult Delete(PassengerNumberSearchModel search) { try { var passengerNumber = _UnitOfWork.PassengerNumberRepository.All() .Include(x => x.Requestes).FirstOrDefault(x => x.Id == search.Id); if (passengerNumber == null) { return(new HttpStatusCodeResult(404, "NotFound")); } else { if (!passengerNumber.Requestes.Any()) { _UnitOfWork.PassengerNumberRepository.Delete(passengerNumber); _UnitOfWork.Commit(); return(RedirectToAction("Search", new { Page = search.Page, PageSize = search.PageSize })); } else { return(new HttpStatusCodeResult(404, "NotFound")); } } } catch (Exception e) { return(new HttpStatusCodeResult(404, "NotFound")); } }