Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Web.Mvc;
- using PJRamosWS.Models;
- using System.Linq;
- using System.Collections.Generic;
- namespace PJRamosWS.Controllers
- {
- public class ServicesController : Controller
- {
- PJRamosEntity context = new PJRamosEntity();
- //
- // GET: /Home/
- public ActionResult Index(int? Type, int? PageNo)
- {
- if (Type != null)
- {
- int max = 8;
- IEnumerable<Services> services = from s in context.Services
- where s.ServiceType == Type
- select s;
- int TotalServices = services.ToList().Count;
- List<Services> auxS = new List<Services>();
- if (TotalServices > max)
- {
- if (PageNo == null)
- PageNo = 1;
- ViewBag.PageNo = PageNo;
- double num = ((double)TotalServices) / (double)max;
- int CertNum = (int)num;
- if (CertNum != num)
- CertNum++;
- if (CertNum <= PageNo)
- PageNo = CertNum;
- ViewBag.TotalPages = CertNum;
- int? start = (PageNo * max) - max;
- int? count = PageNo * max;
- double parse = ((double)PageNo * (double)max) - (double)TotalServices;
- if (parse >= 0)
- count -= (int)parse;
- for (; start != count; start++)
- {
- if (services.ToList()[(int)start] == null)
- break;
- auxS.Add(services.ToList()[(int)start]);
- }
- }
- else
- {
- auxS = services.ToList();
- //PageNo = 0;
- ViewBag.PageNo = null;
- ViewBag.TotalPages = 1;
- }
- var aux = from s in context.ServiceTypes
- where s.id == Type
- select s.Type;
- ViewBag.Type = aux.ToList()[0];
- ViewBag.TypeID = Type;
- return View("ServicesList", auxS);
- }
- else
- {
- IEnumerable<ServiceTypes> services = from s in context.ServiceTypes
- select s;
- return View(services);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement