631 lines
19 KiB
C#
631 lines
19 KiB
C#
using Fab2ApprovalSystem.DMO;
|
|
using Fab2ApprovalSystem.Models;
|
|
using Kendo.Mvc.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Kendo.Mvc.Extensions;
|
|
using Fab2ApprovalSystem.Misc;
|
|
|
|
|
|
|
|
namespace Fab2ApprovalSystem.Controllers
|
|
{
|
|
[Authorize]
|
|
[SessionExpireFilter]
|
|
public class AdminController : Controller
|
|
{
|
|
// GET: /Admin/
|
|
UserAccountDMO userDMO = new UserAccountDMO();
|
|
AdminDMO adminDMO = new AdminDMO();
|
|
TrainingDMO trainingDMO = new TrainingDMO();
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult Index()
|
|
{
|
|
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
var model = userDMO.GetAllUsers();
|
|
return View(model);
|
|
}
|
|
else
|
|
return Content("Not Autthorized");
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult AssignRoles()
|
|
{
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
ViewBag.ToplevelNode = GetRoles_SubRolesList();
|
|
return View();
|
|
}
|
|
else
|
|
return Content("Not Autthorized");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public ActionResult GetAllUserList([DataSourceRequest] DataSourceRequest request)
|
|
{
|
|
IEnumerable<LoginModel> userlist = userDMO.GetAllUsers();
|
|
return Json(userlist, JsonRequestBehavior.AllowGet);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// For the Administration of the Users
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public ActionResult GetGridUserList([DataSourceRequest] DataSourceRequest request)
|
|
{
|
|
return Json(userDMO.GetAllUsers().ToDataSourceResult(request));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="subRole"></param>
|
|
/// <returns></returns>
|
|
public JsonResult GetAllUserListBySubRole(int subRole)
|
|
{
|
|
IEnumerable<LoginModel> userlist = adminDMO.GetAllUsersBySubRole(subRole);
|
|
return Json(userlist, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public JsonResult AllSubRoles(string showInactiveRoles = "")
|
|
{
|
|
List<Role> roles = adminDMO.GetSubRoles();
|
|
|
|
ParentChildModel parent;
|
|
ParentChildModel child = new ParentChildModel();
|
|
|
|
List<ParentChildModel> newRoles = new List<ParentChildModel>();
|
|
foreach (Role r in roles)
|
|
{
|
|
parent = new ParentChildModel();
|
|
parent.id = r.RoleID;
|
|
parent.parentid = -1;
|
|
parent.text = r.RoleName;
|
|
parent.value = r.RoleID.ToString();
|
|
|
|
foreach (SubRole sr in r.SubRoles)
|
|
{
|
|
if (sr.Inactive)
|
|
{
|
|
// hide inactive roles unless parameter says otherwise
|
|
if (showInactiveRoles.Equals("true") == false)
|
|
continue;
|
|
}
|
|
|
|
child = new ParentChildModel();
|
|
child.id = sr.SubRoleID;
|
|
child.parentid = r.RoleID;
|
|
child.text = sr.SubRoleCategoryItem + (sr.Inactive ? " (Inactive)" : "");
|
|
child.value = sr.SubRoleID.ToString();
|
|
newRoles.Add(child);
|
|
}
|
|
|
|
newRoles.Add(parent);
|
|
};
|
|
|
|
|
|
return Json(newRoles, JsonRequestBehavior.AllowGet);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
/// <summary>
|
|
///OBSOLETE FUNCTION BELOW FOR THE KENDO TREEVIEW
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private IEnumerable<TreeViewItemModel> GetRoles_SubRolesList()
|
|
{
|
|
|
|
List<Role> roles = adminDMO.GetSubRoles();
|
|
|
|
|
|
List<TreeViewItemModel> ToplevelNode = new List<TreeViewItemModel>();
|
|
List<TreeViewItemModel> parentList = new List<TreeViewItemModel>();
|
|
List<TreeViewItemModel> childList = new List<TreeViewItemModel>();
|
|
|
|
|
|
TreeViewItemModel parent = new TreeViewItemModel();
|
|
TreeViewItemModel child = new TreeViewItemModel();
|
|
|
|
|
|
foreach (Role r in roles)
|
|
{
|
|
parent = new TreeViewItemModel();
|
|
parent.HasChildren = true;
|
|
parent.Text = r.RoleName;
|
|
parent.Id = r.RoleID.ToString();
|
|
|
|
|
|
foreach (SubRole sr in r.SubRoles)
|
|
{
|
|
child = new TreeViewItemModel();
|
|
child.Text = sr.SubRoleCategoryItem;
|
|
child.Id = sr.SubRoleID.ToString();
|
|
|
|
parent.Items.Add(child);
|
|
}
|
|
|
|
ToplevelNode.Add(parent);
|
|
};
|
|
|
|
|
|
|
|
return ToplevelNode;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="subRole"></param>
|
|
/// <param name="users"></param>
|
|
/// <returns></returns>
|
|
public ActionResult AddUserRoles(int subRole, string users)
|
|
{
|
|
|
|
adminDMO.AddUserRoles(subRole, users);
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="subRole"></param>
|
|
/// <param name="users"></param>
|
|
/// <returns></returns>
|
|
public ActionResult DeleteUserRoles(int subRole, string users)
|
|
{
|
|
|
|
adminDMO.DeleteUserRoles(subRole, users);
|
|
return View();
|
|
}
|
|
|
|
|
|
//
|
|
// GET: /Workflow/Details/5
|
|
public ActionResult Details(int id)
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//
|
|
// GET: /Workflow/Create
|
|
public ActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//
|
|
// POST: /Workflow/Create
|
|
[HttpPost]
|
|
public ActionResult Create(FormCollection collection)
|
|
{
|
|
try
|
|
{
|
|
// TODO: Add insert logic here
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
catch
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult BatchUpdateUser([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<LoginModel> model)
|
|
{
|
|
//if (model != null && ModelState.IsValid)
|
|
//{
|
|
// userDMO.UpdateUser(model);
|
|
//}
|
|
|
|
|
|
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
|
|
}
|
|
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult UpdateUser([DataSourceRequest] DataSourceRequest request, LoginModel model)
|
|
{
|
|
if (model != null && ModelState.IsValid)
|
|
{
|
|
userDMO.UpdateUser(model);
|
|
}
|
|
|
|
|
|
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult DeleteUser([DataSourceRequest] DataSourceRequest request, LoginModel model)
|
|
{
|
|
if (model != null && ModelState.IsValid)
|
|
{
|
|
userDMO.DeleteUser(model);
|
|
trainingDMO.DeleteAssignmentByUserId(model.UserID);
|
|
}
|
|
|
|
|
|
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult InsertUser([DataSourceRequest] DataSourceRequest request, LoginModel model)
|
|
{
|
|
|
|
try
|
|
{
|
|
if (model != null && ModelState.IsValid)
|
|
{
|
|
userDMO.InsertUser(model);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// TODO
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult EnableOOOStatus(int oooUserID, int delegatedTo, DateTime startDate, DateTime endDate)
|
|
{
|
|
int returnValue = MiscDMO.EnableOOOStatus(oooUserID, delegatedTo, startDate, endDate);
|
|
if (returnValue == 3) // the delegator is already a delegator to someone else
|
|
{
|
|
return Content("3");
|
|
}
|
|
else
|
|
return Content("");
|
|
|
|
// TODO - Send an email to the OOO person and to the Delegated person
|
|
//return View();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="oooUserID"></param>
|
|
public void ExpireOOOStatus(int oooUserID)
|
|
{
|
|
MiscDMO.ExpireOOOStatus(oooUserID);
|
|
// TODO - Does it need to send an email
|
|
}
|
|
public ActionResult ManageTrainingGroups()
|
|
{
|
|
//List<TrainingGroup> allGroups = GetTrainingGroups();
|
|
//return View(allGroups);
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
ViewBag.AllGroups = GetTrainingGroups();
|
|
return View();
|
|
}
|
|
else
|
|
return Content("Not Autthorized");
|
|
}
|
|
public void RefreshGroups()
|
|
{
|
|
ViewBag.AllGroups = GetTrainingGroups();
|
|
}
|
|
public ActionResult TrainingGroups()
|
|
{
|
|
List<TrainingGroup> trainingGroups = adminDMO.GetTrainingGroups();
|
|
return PartialView(trainingGroups);
|
|
}
|
|
public List<TrainingGroup> GetTrainingGroups()
|
|
{
|
|
|
|
List<TrainingGroup> TrainingGroups = adminDMO.GetTrainingGroups();
|
|
|
|
|
|
//List<TreeViewItemModel> ToplevelNode = new List<TreeViewItemModel>();
|
|
//List<TreeViewItemModel> parentList = new List<TreeViewItemModel>();
|
|
//List<TreeViewItemModel> childList = new List<TreeViewItemModel>();
|
|
|
|
|
|
//TreeViewItemModel parent = new TreeViewItemModel();
|
|
//TreeViewItemModel child = new TreeViewItemModel();
|
|
//parent = new TreeViewItemModel();
|
|
//parent.HasChildren = true;
|
|
//parent.Text = "Training Groups";
|
|
|
|
//foreach (TrainingGroup group in TrainingGroups)
|
|
//{
|
|
|
|
|
|
// child = new TreeViewItemModel();
|
|
// child.Text = group.TrainingGroupName;
|
|
// child.Id = group.TrainingGroupID.ToString();
|
|
// parent.Items.Add(child);
|
|
//}
|
|
//ToplevelNode.Add(parent);
|
|
////foreach (Role r in roles)
|
|
////{
|
|
//// parent = new TreeViewItemModel();
|
|
//// parent.HasChildren = true;
|
|
//// parent.Text = r.RoleName;
|
|
//// parent.Id = r.RoleID.ToString();
|
|
|
|
|
|
//// foreach (SubRole sr in r.SubRoles)
|
|
//// {
|
|
//// child = new TreeViewItemModel();
|
|
//// child.Text = sr.SubRoleCategoryItem;
|
|
//// child.Id = sr.SubRoleID.ToString();
|
|
|
|
//// parent.Items.Add(child);
|
|
//// }
|
|
|
|
//// ToplevelNode.Add(parent);
|
|
////};
|
|
|
|
|
|
|
|
return TrainingGroups;
|
|
|
|
}
|
|
public ActionResult AddNewTrainingGroup(string groupName)
|
|
{
|
|
try
|
|
{
|
|
adminDMO.AddNewTrainingGroup(groupName);
|
|
return Json(new {test = "Succesfully saved" });
|
|
}
|
|
catch
|
|
{
|
|
return Content("Unable to Save Group", "application/json");
|
|
}
|
|
|
|
}
|
|
public ActionResult DeleteTrainingGroup(int groupID)
|
|
{
|
|
try
|
|
{
|
|
adminDMO.DeleteTrainingGroup(groupID);
|
|
return Json(new { response = "Successfully Deleted" });
|
|
}
|
|
catch
|
|
{
|
|
return Json(new { response = "Unsuccessfully Deleted" });
|
|
}
|
|
}
|
|
public ActionResult ViewTrainingGroup(int TrainingGroupID)
|
|
{
|
|
ViewBag.GroupID = TrainingGroupID;
|
|
return View();
|
|
}
|
|
public ActionResult TrainingGroupPartial(int TrainingGroupID)
|
|
{
|
|
ViewBag.AllUsers = userDMO.GetAllUsers();
|
|
ViewBag.TrainingGroupId = TrainingGroupID;
|
|
List<TrainingGroupMember> trainingGroupMembers = adminDMO.GetTrainingGroupMembers(TrainingGroupID);
|
|
return PartialView(trainingGroupMembers);
|
|
}
|
|
public ActionResult AddToGroup(int userId, int groupId)
|
|
{
|
|
adminDMO.AddUserToGroup(userId, groupId);
|
|
return Json(new { test = "Succesfully saved" });
|
|
}
|
|
public ActionResult DeleteFromGroup(int userId, int groupId)
|
|
{
|
|
adminDMO.DeleteFromGroup(userId, groupId);
|
|
return Json(new { test = "Succesfully removed" });
|
|
}
|
|
public ActionResult JobSchedulerConfiguration()
|
|
{
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
|
|
return View();
|
|
}
|
|
else
|
|
return Content("Not Autthorized");
|
|
}
|
|
public ActionResult TrainingReportConfig()
|
|
{
|
|
ViewBag.AllUsers = userDMO.GetAllUsers();
|
|
List<TrainingReportUser> currentTrainingReportUsersIds = adminDMO.GetTrainingReportUsers();
|
|
List<LoginModel> currentTrainingReportUsers = new List<LoginModel>();
|
|
|
|
foreach (TrainingReportUser id in currentTrainingReportUsersIds)
|
|
{
|
|
currentTrainingReportUsers.Add(userDMO.GetUserByID(id.UserId));
|
|
}
|
|
ViewBag.CurrentReportUsers = currentTrainingReportUsers;
|
|
return PartialView();
|
|
}
|
|
public ActionResult TECNNotificationConfig()
|
|
{
|
|
ViewBag.AllUsers = userDMO.GetAllUsers();
|
|
List<TECNNotificationsUser> currentTECNNotificationUsersIds = adminDMO.GetTECNNotificationUsers();
|
|
List<LoginModel> currentTECNNotificationUsers = new List<LoginModel>();
|
|
|
|
foreach (TECNNotificationsUser id in currentTECNNotificationUsersIds)
|
|
{
|
|
currentTECNNotificationUsers.Add(userDMO.GetUserByID(id.UserId));
|
|
}
|
|
ViewBag.CurrentReportUsers = currentTECNNotificationUsers;
|
|
return PartialView();
|
|
}
|
|
public ActionResult AddToTrainingReport(int userId)
|
|
{
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
//Check to make sure user is not apart of the group already
|
|
bool userExists = false;
|
|
//bool userValid = true;
|
|
List<TrainingReportUser> existingUsers = adminDMO.GetTrainingReportUsers();
|
|
foreach (var item in existingUsers)
|
|
{
|
|
if (item.UserId == userId)
|
|
{
|
|
userExists = true;
|
|
}
|
|
}
|
|
//Check if user is valid
|
|
var validUser = userDMO.GetUserByID(userId);
|
|
|
|
//Add to group
|
|
if (!userExists && validUser != null)
|
|
{
|
|
adminDMO.TrainingReportAddUser(userId);
|
|
return Json("Success Added");
|
|
}
|
|
else
|
|
{
|
|
return Content("User either doesn't exist OR is already added");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Content("Not Autthorized");
|
|
}
|
|
}
|
|
public ActionResult AddToTECNNotification(int userId)
|
|
{
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
//Check to make sure user is not apart of the group already
|
|
bool userExists = false;
|
|
//bool userValid = true;
|
|
List<TECNNotificationsUser> existingUsers = adminDMO.GetTECNNotificationUsers();
|
|
foreach (var item in existingUsers)
|
|
{
|
|
if (item.UserId == userId)
|
|
{
|
|
userExists = true;
|
|
}
|
|
}
|
|
//Check if user is valid
|
|
var validUser = userDMO.GetUserByID(userId);
|
|
|
|
//Add to group
|
|
if (!userExists && validUser != null)
|
|
{
|
|
try
|
|
{
|
|
adminDMO.TECNExpirationAddUser(userId);
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
string exception = e.Message;
|
|
return Content(exception);
|
|
}
|
|
|
|
|
|
return Json("Success Added");
|
|
}
|
|
else
|
|
{
|
|
return Content("User either doesn't exist OR is already added");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Content("Not Autthorized");
|
|
}
|
|
}
|
|
public ActionResult DeleteFromTrainingReport(int userId)
|
|
{
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
try
|
|
{
|
|
adminDMO.TrainingReportDeleteUser(userId);
|
|
return Content("Successfully Deleted");
|
|
}
|
|
catch
|
|
{
|
|
return Content("Error while trying to delete");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Content("Not Autthorized");
|
|
}
|
|
}
|
|
public ActionResult DeleteFromTECNNotification(int userId)
|
|
{
|
|
if ((bool)Session[GlobalVars.IS_ADMIN])
|
|
{
|
|
try
|
|
{
|
|
adminDMO.TECNExpirationDeleteUser(userId);
|
|
return Content("Successfully Deleted");
|
|
}
|
|
catch
|
|
{
|
|
return Content("Error while trying to delete");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Content("Not Autthorized");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|