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
|
|
|
|
|
{
|
2014-11-01 03:28:16 +08:00
|
|
|
|
public static int pageSize { get { return 15; } }
|
2014-10-11 06:57:02 +08:00
|
|
|
|
//
|
|
|
|
|
// GET: /build/
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
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));
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return View("index", pageBuilds);
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 07:39:18 +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));
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return View("index", pageBuilds);
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 07:39:18 +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));
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return View("index", pageBuilds);
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 07:39:18 +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));
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return View("index", pageBuilds);
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /build/Info/5
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
public ActionResult info(int id)
|
2014-10-11 06:57:02 +08:00
|
|
|
|
{
|
|
|
|
|
Build b = Build.SelectById(id);
|
2014-10-21 20:53:27 +08:00
|
|
|
|
|
|
|
|
|
if(b == null)
|
|
|
|
|
{
|
|
|
|
|
return new HttpNotFoundResult();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-11 06:57:02 +08:00
|
|
|
|
return View(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /build/Create
|
|
|
|
|
[Authorize]
|
2014-10-29 07:39:18 +08:00
|
|
|
|
public ActionResult create()
|
2014-10-11 06:57:02 +08:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// POST: /build/Create
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpPost]
|
2014-10-29 07:39:18 +08:00
|
|
|
|
public ActionResult create(Build build)
|
2014-10-11 06:57:02 +08:00
|
|
|
|
{
|
|
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
build.Added = DateTime.Now;
|
2014-11-01 03:28:16 +08:00
|
|
|
|
build.Modified = DateTime.Now;
|
2014-10-11 06:57:02 +08:00
|
|
|
|
Build.Insert(build);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View(build);
|
|
|
|
|
}
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return RedirectToAction("index");
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return View(build);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /build/Edit/5
|
|
|
|
|
[Authorize]
|
2014-10-29 07:39:18 +08:00
|
|
|
|
public ActionResult edit(long id)
|
2014-10-11 06:57:02 +08:00
|
|
|
|
{
|
|
|
|
|
Build b = Build.SelectById(id);
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return View("create", b);
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// POST: /build/Edit/5
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpPost]
|
2014-10-29 07:39:18 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return RedirectToAction("index");
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-10-29 07:39:18 +08:00
|
|
|
|
return View("create", build);
|
2014-10-11 06:57:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize(Users = "hounsell")]
|
2014-10-29 07:39:18 +08:00
|
|
|
|
public ActionResult delete(long id)
|
2014-10-11 06:57:02 +08:00
|
|
|
|
{
|
|
|
|
|
Build.DeleteById(id);
|
|
|
|
|
return Redirect("/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|