using EnVisage.App_Start; using EnVisage.Code.BLL; using Kendo.Mvc.UI; using System; using System.ComponentModel; using System.Linq; using System.Web.Mvc; namespace EnVisage.Controllers { [Authorize] public class ContentLockerApiController : Controller { public JsonResult AddLock(String tableId, String fieldId, string timestamp) { var response = ContentLocker.AddLock(tableId, fieldId, User.Identity.GetUserName(), timestamp); return Json(response); } public JsonResult UpdateLock(String tableId, String fieldId) { var response = ContentLocker.UpdateLock(tableId, fieldId, User.Identity.GetUserName()); return Json(response); } public JsonResult IsLock(String tableId, String fieldId) { var response = ContentLocker.IsLocked(tableId, fieldId, User.Identity.GetUserName()); return Json(response); } public JsonResult RemoveLock(String tableId, String fieldId) { var response = ContentLocker.RemoveLock(tableId, fieldId, User.Identity.GetUserName()); return Json(response); } [HttpGet] public ActionResult DropObjectLock(Guid id) { string message = String.Empty; bool errorHappened; if (!id.Equals(Guid.Empty)) { var removedCount = ContentLocker.RemoveAllLocks(id.ToString()); message = removedCount > 0 ? String.Format("Locks for object '{0}' removed successfully (found records: {1})", id, removedCount) : String.Format("Locks for object '{0}' not found", id); errorHappened = false; } else { message = "No lock checks were performed: Object Id must be specified"; errorHappened = true; } ViewBag.Message = message; ViewBag.HasError = errorHappened; return View("~/Views/ContentLocker/DropObjectLock.cshtml"); } [HttpGet] public ActionResult Index() { return View("~/Views/ContentLocker/Index.cshtml"); } [HttpPost] public JsonResult Index([DataSourceRequest]Kendo.Mvc.UI.DataSourceRequest request) { string orderBy = "ReleaseTimeUTC"; var isOrderAsc = false; if (request.Sorts.Any()) { orderBy = request.Sorts.First().Member; isOrderAsc = request.Sorts.First().SortDirection == ListSortDirection.Ascending ? true : false; } return Json(ContentLocker.GetLockedObjects(request.PageSize, (request.Page - 1) * request.PageSize, orderBy, isOrderAsc), JsonRequestBehavior.AllowGet); } } }