public ActionResult Index(ReportToAdminViewModel collection) { long totalCount; var request = new FilteredModel <ReportToAdmin> { PageIndex = collection.ThisPageIndex, Order = collection.PageOrder, OrderBy = collection.PageOrderBy }; var offset = (request.PageIndex - 1) * request.PageSize; var result = _mapper.Map <IList <ReportToAdminViewModel> >(_reportToAdminService.GetPaging(_mapper.Map <ReportToAdmin>(collection), out totalCount, request.OrderBy, request.Order, offset, request.PageSize)); if (!result.Any() && totalCount > 0 && request.PageIndex > 1) { request.PageIndex = (int)(totalCount / request.PageSize); if (totalCount % request.PageSize > 0) { request.PageIndex++; } result = _mapper.Map <IList <ReportToAdminViewModel> >(_reportToAdminService.GetPaging(_mapper.Map <ReportToAdmin>(collection), out totalCount, request.OrderBy, request.Order, offset, request.PageSize)); } ViewBag.OnePageOfEntries = new StaticPagedList <ReportToAdminViewModel>(result, request.PageIndex, request.PageSize, (int)totalCount); ViewBag.SearchModel = collection; return(View()); }
public ActionResult Delete(int id, ReportToAdminViewModel collection) { try { if (id > 0) { collection.UpdaterId = LogedInAdmin.Id; _reportToAdminService.Delete(_mapper.Map <ReportToAdmin>(collection)); return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, GeneralMessages.EmptyId); return(View(collection)); } catch (Exception ex) { _logger.Error(ex); if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource)) { ModelState.AddModelError(string.Empty, ex.Message); } else { ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError); } return(View(collection)); } }