BuildFeed/Controllers/buildController.cs

163 lines
4.5 KiB
C#
Raw Normal View History

2014-10-11 06:57:02 +08:00
using BuildFeed.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace BuildFeed.Controllers
{
public class buildController : Controller
{
public static int pageSize { get { return 15; } }
2014-10-11 06:57:02 +08:00
//
// GET: /build/
public ActionResult index(int page = 1)
2014-10-11 06:57:02 +08:00
{
var builds = Build.SelectInBuildOrder();
var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize));
return View(pageBuilds);
}
public ActionResult year(int year, int page = 1)
2014-10-11 06:57:02 +08:00
{
var builds = Build.SelectInBuildOrder().Where(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year);
var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize));
return View("index", pageBuilds);
2014-10-11 06:57:02 +08:00
}
public ActionResult lab(string lab, int page = 1)
2014-10-11 06:57:02 +08:00
{
var builds = Build.SelectInBuildOrder().Where(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower()));
var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize));
return View("index", pageBuilds);
2014-10-11 06:57:02 +08:00
}
public ActionResult version(int major, int minor, int page = 1)
2014-10-11 06:57:02 +08:00
{
var builds = Build.SelectInBuildOrder().Where(b => b.MajorVersion == major && b.MinorVersion == minor);
var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize));
return View("index", pageBuilds);
2014-10-11 06:57:02 +08:00
}
public ActionResult source(TypeOfSource source, int page = 1)
2014-10-11 06:57:02 +08:00
{
var builds = Build.SelectInBuildOrder().Where(b => b.SourceType == source);
var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize));
return View("index", pageBuilds);
2014-10-11 06:57:02 +08:00
}
//
// GET: /build/Info/5
public ActionResult info(int id)
2014-10-11 06:57:02 +08:00
{
Build b = Build.SelectById(id);
if(b == null)
{
return new HttpNotFoundResult();
}
2014-10-11 06:57:02 +08:00
return View(b);
}
//
// GET: /build/Create
[Authorize]
public ActionResult create()
2014-10-11 06:57:02 +08:00
{
return View();
}
//
// POST: /build/Create
[Authorize]
[HttpPost]
public ActionResult create(Build build)
2014-10-11 06:57:02 +08:00
{
if (ModelState.IsValid)
{
try
{
build.Added = DateTime.Now;
build.Modified = DateTime.Now;
2014-10-11 06:57:02 +08:00
Build.Insert(build);
}
catch
{
return View(build);
}
return RedirectToAction("index");
2014-10-11 06:57:02 +08:00
}
else
{
return View(build);
}
}
//
// GET: /build/Edit/5
[Authorize]
public ActionResult edit(long id)
2014-10-11 06:57:02 +08:00
{
Build b = Build.SelectById(id);
return View("create", b);
2014-10-11 06:57:02 +08:00
}
//
// POST: /build/Edit/5
[Authorize]
[HttpPost]
public ActionResult edit(long id, Build build)
2014-10-11 06:57:02 +08:00
{
if (ModelState.IsValid)
{
try
{
Build.Update(build);
}
catch
{
return View();
}
return RedirectToAction("index");
2014-10-11 06:57:02 +08:00
}
else
{
return View("create", build);
2014-10-11 06:57:02 +08:00
}
}
[Authorize(Users = "hounsell")]
public ActionResult delete(long id)
2014-10-11 06:57:02 +08:00
{
Build.DeleteById(id);
return Redirect("/");
}
}
}