BuildFeed/Controllers/buildController.cs

162 lines
4.6 KiB
C#
Raw Normal View History

2014-10-11 06:57:02 +08:00
using BuildFeed.Models;
using System;
using System.Linq;
using System.Web.Mvc;
namespace BuildFeed.Controllers
{
public class buildController : Controller
{
public static int pageSize { get { return 20; } }
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));
2015-01-30 05:44:54 +08:00
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey() { Type = MetaType.Lab, Value = lab });
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("info", new { id = build.Id });
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("create", build);
2014-10-11 06:57:02 +08:00
}
return RedirectToAction("info", new { id = build.Id });
2014-10-11 06:57:02 +08:00
}
else
{
return View("create", build);
2014-10-11 06:57:02 +08:00
}
}
2014-12-16 22:43:26 +08:00
[Authorize(Roles = "Administrators")]
public ActionResult delete(long id)
2014-10-11 06:57:02 +08:00
{
Build.DeleteById(id);
return Redirect("/");
}
}
}