Moved System.IO references from DMO classes to Static Helpers
Removed nugetSource from pipeline Removed more comments Created Static Classes for most DMO / Controller Classes Push ConfigurationManager.AppSettings to controller Align Tests with other Projects
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
using Fab2ApprovalSystem.DMO;
|
||||
using Fab2ApprovalSystem.Misc;
|
||||
using Fab2ApprovalSystem.Models;
|
||||
@ -6,12 +12,6 @@ using Fab2ApprovalSystem.ViewModels;
|
||||
|
||||
using Kendo.Mvc.Extensions;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Fab2ApprovalSystem.Controllers;
|
||||
|
||||
[Authorize]
|
||||
@ -22,7 +22,7 @@ public class TrainingController : Controller {
|
||||
AdminDMO adminDMO = new AdminDMO();
|
||||
TrainingDMO trainingDMO = new TrainingDMO();
|
||||
ECN_DMO ecnDMO = new ECN_DMO();
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly AppSettings _AppSettings = GlobalVars.AppSettings;
|
||||
|
||||
// GET: Training
|
||||
public ActionResult Index() {
|
||||
@ -32,7 +32,7 @@ public class TrainingController : Controller {
|
||||
public int Create(int ecnId) {
|
||||
ECN_DMO ecnDMO = new ECN_DMO();
|
||||
|
||||
//Delete old training if exists
|
||||
// Delete old training if exists
|
||||
int oldTrainingId = trainingDMO.GetTrainingId(ecnId);
|
||||
if (oldTrainingId != null && oldTrainingId != 0) {
|
||||
trainingDMO.DeleteTraining(oldTrainingId);
|
||||
@ -57,34 +57,34 @@ public class TrainingController : Controller {
|
||||
}
|
||||
public ActionResult AddUserToTrainingAdHoc(int trainingId, int traineeId, int ecnId) {
|
||||
if ((bool)Session[GlobalVars.IS_ADMIN]) {
|
||||
//Get ECN
|
||||
// Get ECN
|
||||
ECN ecn = ecnDMO.GetECN(ecnId);
|
||||
|
||||
//Get User
|
||||
// Get User
|
||||
LoginModel user = userDMO.GetUserByID(traineeId);
|
||||
|
||||
//Get Training
|
||||
// Get Training
|
||||
Training training = trainingDMO.GetTraining(trainingId);
|
||||
if (ecn != null) {
|
||||
if (user != null) {
|
||||
if (training != null) {
|
||||
if (!trainingDMO.IsUserAssigned(traineeId, trainingId)) {
|
||||
if (training.DeletedDate == null && !ecn.Deleted) {
|
||||
//Both the ECN and training still exist
|
||||
// Both the ECN and training still exist
|
||||
if (training.CompletedDate != null) {
|
||||
//Training is completed and now we need to re-open it.
|
||||
// Training is completed and now we need to re-open it.
|
||||
trainingDMO.reOpenTraining(trainingId);
|
||||
int assignmentId = trainingDMO.CreateAssignment(trainingId, traineeId);
|
||||
NotifyTrainee(traineeId, assignmentId, ecnId, ecn.Title);
|
||||
return Content("Success");
|
||||
} else {
|
||||
//training is still open, just add a user and notify
|
||||
// training is still open, just add a user and notify
|
||||
int assignmentId = trainingDMO.CreateAssignment(trainingId, traineeId);
|
||||
NotifyTrainee(traineeId, assignmentId, ecnId, ecn.Title);
|
||||
return Content("Success");
|
||||
}
|
||||
} else {
|
||||
//Ecn or training task have been deleted.
|
||||
// Ecn or training task have been deleted.
|
||||
return Content("Training or ECN has been deleted.");
|
||||
}
|
||||
} else {
|
||||
@ -116,9 +116,9 @@ public class TrainingController : Controller {
|
||||
if (training != null) {
|
||||
if (training.DeletedDate == null && !ecn.Deleted) {
|
||||
if (training.CompletedDate != null) {
|
||||
//Training is completed and now we need to re-open it.
|
||||
// Training is completed and now we need to re-open it.
|
||||
foreach (int id in groupMemberIds) {
|
||||
//Check to make sure user doesn't have an active assignment for this training
|
||||
// Check to make sure user doesn't have an active assignment for this training
|
||||
if (!trainingDMO.IsUserAssigned(id, trainingId)) {
|
||||
usersAdded++;
|
||||
int assignmentId = trainingDMO.CreateAssignment(trainingId, id);
|
||||
@ -129,9 +129,9 @@ public class TrainingController : Controller {
|
||||
trainingDMO.reOpenTraining(trainingId);
|
||||
}
|
||||
} else {
|
||||
//training is still open, just add a users and notify
|
||||
// training is still open, just add a users and notify
|
||||
foreach (int id in groupMemberIds) {
|
||||
//Check to make sure user doesn't have an active assignment for this training
|
||||
// Check to make sure user doesn't have an active assignment for this training
|
||||
if (!trainingDMO.IsUserAssigned(id, trainingId)) {
|
||||
usersAdded++;
|
||||
int assignmentId = trainingDMO.CreateAssignment(trainingId, id);
|
||||
@ -178,28 +178,8 @@ public class TrainingController : Controller {
|
||||
|
||||
public void NotifyTrainee(int userId, int assignmentId, int ecnId, string title) {
|
||||
try {
|
||||
string emailSentList = "";
|
||||
string recipient = userDMO.GetUserEmailByID(userId);
|
||||
|
||||
string emailTemplate = "ECNTrainingAssigned.txt";
|
||||
string userEmail = string.Empty;
|
||||
string subject = string.Empty;
|
||||
string senderName = "ECN Training";
|
||||
|
||||
subject = "ECN# " + ecnId + " - Training Assignment Notice - " + title;
|
||||
|
||||
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
|
||||
userEmail = recipient;
|
||||
string[] emailparams = new string[4];
|
||||
emailparams[0] = assignmentId.ToString();
|
||||
emailparams[1] = ecnId.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
//#if(DEBUG)
|
||||
//string SenderEmail = "MesaFabApproval@infineon.com";
|
||||
//userEmail = "jonathan.ouellette@infineon.com";
|
||||
//#endif
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
TrainingHelper.NotifyTrainee(_AppSettings, userId, assignmentId, ecnId, title, recipient);
|
||||
} catch (Exception e) {
|
||||
string detailedException = "";
|
||||
try {
|
||||
@ -220,13 +200,12 @@ public class TrainingController : Controller {
|
||||
|
||||
public ActionResult ViewTrainingDocsPartial(int trainingAssignmentId) {
|
||||
ViewBag.trainingAssignmentId = trainingAssignmentId;
|
||||
//IEnumerable<TrainingDocAck> attachments = ecnDMO.GetECNAttachments(ecnNumber);
|
||||
IEnumerable<TrainingDocAck> attachments = trainingDMO.GetAssignedDocs(trainingAssignmentId);
|
||||
return PartialView(attachments);
|
||||
}
|
||||
|
||||
public ActionResult AcknowledgeDocument(int trainingAssignmentID, int trainingDocAckID) {
|
||||
//Check to see if acknowledgement is valid(Security Feature to protect data integrity)
|
||||
// Check to see if acknowledgement is valid(Security Feature to protect data integrity)
|
||||
if (trainingDMO.CheckValidDocAck(trainingDocAckID)) {
|
||||
trainingDMO.AcknowledgeDocument(trainingDocAckID);
|
||||
bool isFinishedTrainingAssignment = trainingDMO.CheckTrainingAssignmentStatus(trainingAssignmentID);
|
||||
@ -272,7 +251,7 @@ public class TrainingController : Controller {
|
||||
public ActionResult TrainingReportsView(int? filterType, string filterValue) {
|
||||
ViewBag.TrainingGroups = adminDMO.GetTrainingGroups();
|
||||
IEnumerable<Training> trainingList = trainingDMO.GetAllTrainings();
|
||||
//Group Filter
|
||||
// Group Filter
|
||||
if (filterType == 1 && filterValue != "") {
|
||||
ViewBag.GroupFilter = filterValue;
|
||||
List<Training> filteredTraining = new List<Training>();
|
||||
@ -287,27 +266,27 @@ public class TrainingController : Controller {
|
||||
trainingList = filteredTraining;
|
||||
return PartialView(trainingList);
|
||||
}
|
||||
//Status Filter
|
||||
// Status Filter
|
||||
if (filterType == 2 && filterValue != "") {
|
||||
List<Training> filteredTraining = new List<Training>();
|
||||
switch (filterValue) {
|
||||
case "1":
|
||||
//Completed
|
||||
// Completed
|
||||
filteredTraining = (from a in trainingList where a.Status == true && a.Deleted != true select a).ToList();
|
||||
break;
|
||||
case "2":
|
||||
//In Progress
|
||||
// In Progress
|
||||
filteredTraining = (from a in trainingList where a.Status != true && a.Deleted != true select a).ToList();
|
||||
break;
|
||||
case "3":
|
||||
//Cancelled
|
||||
// Cancelled
|
||||
filteredTraining = (from a in trainingList where a.Deleted == true select a).ToList();
|
||||
break;
|
||||
}
|
||||
trainingList = filteredTraining;
|
||||
return PartialView(trainingList);
|
||||
}
|
||||
//Default return all.
|
||||
// Default return all.
|
||||
else {
|
||||
return PartialView(trainingList);
|
||||
}
|
||||
@ -323,9 +302,8 @@ public class TrainingController : Controller {
|
||||
ViewBag.ECNTitle = ECNTitle;
|
||||
ViewBag.trainingID = trainingID;
|
||||
IEnumerable<TrainingAssignment> trainingAssignments = trainingDMO.GetAllTrainingAssignments(trainingID);
|
||||
//Calculate Percent Complete:
|
||||
// Calculate Percent Complete:
|
||||
float percentComplete = 0;
|
||||
//float assignmentCount = trainingAssignments.Count();
|
||||
float assignmentCount = (from a in trainingAssignments where a.Deleted != true select a).Count();
|
||||
float totalCompleted = 0;
|
||||
foreach (TrainingAssignment assignment in trainingAssignments) {
|
||||
@ -351,15 +329,15 @@ public class TrainingController : Controller {
|
||||
List<TrainingAssignment> filteredTraining = new List<TrainingAssignment>();
|
||||
switch (statusFilter) {
|
||||
case "1":
|
||||
//Completed
|
||||
// Completed
|
||||
filteredTraining = (from a in trainingAssignments where a.status == true && a.Deleted != true select a).ToList();
|
||||
break;
|
||||
case "2":
|
||||
//In Progress
|
||||
// In Progress
|
||||
filteredTraining = (from a in trainingAssignments where a.status != true && a.Deleted != true select a).ToList();
|
||||
break;
|
||||
case "3":
|
||||
//Cancelled
|
||||
// Cancelled
|
||||
filteredTraining = (from a in trainingAssignments where a.Deleted == true select a).ToList();
|
||||
break;
|
||||
default:
|
||||
@ -367,7 +345,6 @@ public class TrainingController : Controller {
|
||||
break;
|
||||
}
|
||||
trainingAssignments = filteredTraining;
|
||||
//return PartialView(trainingList);
|
||||
}
|
||||
|
||||
return PartialView(trainingAssignments);
|
||||
@ -427,7 +404,7 @@ public class TrainingController : Controller {
|
||||
IEnumerable<Training> AllTrainings = trainingDMO.GetTrainings();
|
||||
ViewBag.TrainingGroups = adminDMO.GetTrainingGroups();
|
||||
ViewBag.AllGroups = trainingDMO.GetTrainingGroups();
|
||||
//Group Filter
|
||||
// Group Filter
|
||||
if (filterType == 1 && filterValue != "") {
|
||||
ViewBag.GroupFilter = filterValue;
|
||||
List<Training> filteredTraining = new List<Training>();
|
||||
@ -455,8 +432,8 @@ public class TrainingController : Controller {
|
||||
trainingDMO.DeleteTrainingAssignment(assignmentId);
|
||||
trainingDMO.DeleteTrainingDocAck(assignmentId);
|
||||
|
||||
//Below checks and updates the training status
|
||||
//TO-DO Put this in its own method.
|
||||
// Below checks and updates the training status
|
||||
// TO-DO Put this in its own method.
|
||||
bool isFinishedTrainingAssignment = trainingDMO.CheckTrainingAssignmentStatus(assignmentId);
|
||||
|
||||
if (isFinishedTrainingAssignment) {
|
||||
@ -479,12 +456,11 @@ public class TrainingController : Controller {
|
||||
public ActionResult ManuallyExecuteECNTraining(int ecnId, int[] trainingGroupsIn) {
|
||||
if ((bool)Session[GlobalVars.IS_ADMIN]) {
|
||||
List<int> newTrainingGroupIds = new List<int>(trainingGroupsIn);
|
||||
//Get ECN
|
||||
ECN ecn = ecnDMO.GetECN(ecnId);
|
||||
if (ecn != null) {
|
||||
if (ecn.CloseDate != null) {
|
||||
if (newTrainingGroupIds.Count > 0) {
|
||||
//Check each assigned group id and see if it's already saved to the ECN
|
||||
// Check each assigned group id and see if it's already saved to the ECN
|
||||
List<int> assignedTrainingGroups = trainingDMO.GetECNAssignedTrainingGroups(ecnId);
|
||||
IEnumerable<int> onlyNewTrainingIds = newTrainingGroupIds.Except(assignedTrainingGroups);
|
||||
try {
|
||||
@ -539,15 +515,14 @@ public class TrainingController : Controller {
|
||||
emailBody += "Please ensure the following users complete their training assignments. ";
|
||||
emailBody += "Dates in red font identify past due training tasks.</p><br />";
|
||||
emailBody += "<style>table,th,td{border: 1px solid black;}</style>";
|
||||
//Get all users set up to receive the training report email.
|
||||
// Get all users set up to receive the training report email.
|
||||
List<TrainingReportUser> trainingReportUsers = adminDMO.GetTrainingReportUsers();
|
||||
List<string> emailList = new List<string>();
|
||||
foreach (TrainingReportUser user in trainingReportUsers) {
|
||||
string userEmail = userDMO.GetUserByID(user.UserId).Email;
|
||||
emailList.Add(userEmail);
|
||||
}
|
||||
//emailList.Add("Chase.Tucker@infineon.com");
|
||||
//Get a list of open trainings
|
||||
// Get a list of open trainings
|
||||
List<Training> openTrainings = trainingDMO.GetAllOpenTrainings();
|
||||
|
||||
foreach (Training training in openTrainings) {
|
||||
|
Reference in New Issue
Block a user