public async Task <ActionResult> Index([Bind(Include = IndexRequestModelValidationIncludeBindings)] IndexRequestModel model) { var viewModel = new IndexViewModel { Content = model.Content, PixelPerModule = model.PixelPerModule }; try { if (this.ModelState.IsValid) { viewModel.Image = await this.encoder.EncodeBase64(model.Content, viewModel.PixelPerModule); } else { this.ModelState.AddModelError(string.Empty, "Invalid data"); } } catch (Exception e) { this.ModelState.AddModelError(nameof(model.Content), e); } return(this.View(viewModel)); }
public async Task <ActionResult> Index([Bind(Include = IndexRequestModelValidationIncludeBindings)] IndexRequestModel model) { var viewModel = new IndexViewModel(model.Type) { Content = model.Content, Width = model.Width, Height = model.Height }; try { if (this.ModelState.IsValid) { viewModel.Image = await this.encoder.EncodeBase64((BarcodeType)model.Type, model.Content, model.Width, model.Height); } else { this.ModelState.AddModelError(string.Empty, "Invalid data"); } } catch (Exception e) { this.ModelState.AddModelError(nameof(model.Content), e.Message); } return(this.View(viewModel)); }
public async Task <PagedList <Owner> > IndexRequest <T>(IndexRequestModel request) where T : class { var pagedList = new PagedList <Owner>(); var list = new List <Owner>(); int count = await _service.Count <Owner>();; var data = Enumerable.Empty <Owner>(); var query = Enumerable.Empty <Owner>(); var searched = false; // Search if (!string.IsNullOrEmpty(request.SearchString)) { query = await OwnerDataFormatting.Search(_service.GetAll <Owner>(), request.SearchString); searched = true; } // Sort if (!string.IsNullOrEmpty(request.SortVariable)) { if (searched) { data = OwnerDataFormatting.Sort <Owner>(query, request.SortVariable); } else { data = OwnerDataFormatting.Sort <Owner>(_service.GetAll <Owner>(), request.SortVariable); } foreach (var item in data) { list.Add(item); } pagedList.Initialize(list.Skip(request.Page * request.PageSize).Take(request.PageSize), request, count); } // Index request without modifiers else { data = OwnerDataFormatting.Sort <Owner>(_service.GetAll <Owner>(), "Date_desc"); foreach (var item in data) { list.Add(item); } pagedList.Initialize(list.Skip(request.Page * request.PageSize).Take(request.PageSize), request, count); } return(pagedList); }
// GET: Test public ActionResult Index(IndexRequestModel indexRequestModel) { IndexResponseModel indexResponseModel = new IndexResponseModel { Num1 = indexRequestModel.Num1, Num2 = indexRequestModel.Num2 }; indexResponseModel.Result = indexResponseModel.Num1 + indexResponseModel.Num2; ViewBag.bag = "viewBag"; ViewData["data"] = "viewData"; return(View(indexResponseModel)); }
public void Initialize(IEnumerable <T> list, IndexRequestModel request, int count) { Page = request.Page; TotalEntries = count; TotalPages = (int)Math.Ceiling(count / (double)request.PageSize); PageEntries = Page * request.PageSize + 1; PageEnd = (PageEntries + list.Count() - 1); if (list.Count() > 0) { this.AddRange(list); } }