Advertisement
FoxTuGa

ASP.NET MVC Page Numeration load by controller

Nov 1st, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System.Web.Mvc;
  2. using PJRamosWS.Models;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace PJRamosWS.Controllers
  7. {
  8.     public class ServicesController : Controller
  9.     {
  10.         PJRamosEntity context = new PJRamosEntity();
  11.         //
  12.         // GET: /Home/
  13.  
  14.         public ActionResult Index(int? Type, int? PageNo)
  15.         {
  16.             if (Type != null)
  17.             {
  18.                 int max = 8;
  19.  
  20.                 IEnumerable<Services> services = from s in context.Services
  21.                                                  where s.ServiceType == Type
  22.                                                  select s;
  23.  
  24.                 int TotalServices = services.ToList().Count;
  25.  
  26.                 List<Services> auxS = new List<Services>();
  27.  
  28.                 if (TotalServices > max)
  29.                 {
  30.                     if (PageNo == null)
  31.                         PageNo = 1;
  32.                     ViewBag.PageNo = PageNo;
  33.  
  34.                     double num = ((double)TotalServices) / (double)max;
  35.                     int CertNum = (int)num;
  36.                     if (CertNum != num)
  37.                         CertNum++;
  38.  
  39.                     if (CertNum <= PageNo)
  40.                         PageNo = CertNum;
  41.  
  42.                     ViewBag.TotalPages = CertNum;
  43.  
  44.                     int? start = (PageNo * max) - max;
  45.                     int? count = PageNo * max;
  46.  
  47.                     double parse = ((double)PageNo * (double)max) - (double)TotalServices;
  48.                     if (parse >= 0)
  49.                         count -= (int)parse;
  50.  
  51.                     for (; start != count; start++)
  52.                     {
  53.                         if (services.ToList()[(int)start] == null)
  54.                             break;
  55.                         auxS.Add(services.ToList()[(int)start]);
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     auxS = services.ToList();
  61.                     //PageNo = 0;
  62.                     ViewBag.PageNo = null;
  63.                     ViewBag.TotalPages = 1;
  64.                 }
  65.  
  66.                 var aux = from s in context.ServiceTypes
  67.                           where s.id == Type
  68.                           select s.Type;
  69.  
  70.                 ViewBag.Type = aux.ToList()[0];
  71.                 ViewBag.TypeID = Type;
  72.  
  73.                 return View("ServicesList", auxS);
  74.             }
  75.             else
  76.             {
  77.  
  78.                 IEnumerable<ServiceTypes> services = from s in context.ServiceTypes
  79.                                                      select s;
  80.                 return View(services);
  81.  
  82.             }
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement