public ActionResult Index() { var model = new NoticeIndexModel(); model.Notices = Notices.Load(); model.Zone = Zone.Load(DBSettings.NoticeZone); return(View(model)); }
public IActionResult Index(NoticeIndexModel model) { try { var recordModels = _noticeService.GetAllNotices(model).OrderByDescending(p => p.CreatedOn); model.Notices = recordModels.ToList(); return(View(model)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public List <NoticeModel> GetAllNotices(NoticeIndexModel model) { using (var unitOfWork = _unitOfWorkFactory.Create()) { var notices = unitOfWork.Notices.GetAllNotices(); notices = notices .SearchByKeyWord(model.SearchKey) .ByPriceFrom(model.PriceFrom) .ByPriceTo(model.PriceTo) .ByCategoryId(unitOfWork, model.CategoryId); int pageSize = 10; int count = notices.Count(); int page = model.Page.HasValue ? model.Page.Value : 1; notices = notices.Skip((page - 1) * pageSize).Take(pageSize); model.PagingModel = new PagingModel(count, page, pageSize); model.Page = page; var models = Mapper.Map <List <NoticeModel> >(notices.ToList()); return(models); } }