public DataValidatorReturn Create(int workOrderID, string clientCode) { DVR = MethodHelper.IsGreaterThanZero("Work Order Number", workOrderID); if (DVR.IsValid == false) { return(DVR); } DVR = MethodHelper.IsParameterEmpty("Client Code", clientCode); if (DVR.IsValid == false) { return(DVR); } if (Find(workOrderID).ItemFound) { DVR.IsValid = false; DVR.ReturnText = "Work Order # " + workOrderID.ToString() + " already exists."; DVR.ItemFound = true; return(DVR); } using (var context = new WorkOrderLogEntities()) { WorkOrderHeader workderOrderHeader = new WorkOrderHeader() { WOHdrID = workOrderID, ClientCode = clientCode, CreatedDate = DateTime.Now.ToLocalTime(), CreatedBy = "SYSTEM" }; try { context.WorkOrderHeaders.Add(workderOrderHeader); context.SaveChanges(); DVR.IsValid = true; DVR.ReturnText = "Work Order #" + workOrderID.ToString() + " Added to the Database."; DVR.ReturnType = workderOrderHeader; } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } } return(DVR); }
public DataValidatorReturn Create(string activityDescription, int activityTypeID) { DVR = MethodHelper.IsParameterEmpty("Activity", activityDescription); if (DVR.IsValid == false) { return(DVR); } if (Find(activityDescription).ItemFound) { DVR.IsValid = false; DVR.ReturnText = activityDescription + " already exists."; DVR.ItemFound = true; return(DVR); } BO_ActivityType bO_ActivityType = new BO_ActivityType(); DVR = bO_ActivityType.Find(activityTypeID); if (DVR.ItemFound == false) { return(DVR); } using (var context = new WorkOrderLogEntities()) { Activity activity = new Activity() { ActivityDescription = activityDescription, ActivityTypeID = activityTypeID }; try { context.Activities.Add(activity); context.SaveChanges(); DVR.IsValid = true; DVR.ReturnText = "Activity: " + activityDescription + " Added to the Database."; DVR.ReturnType = activity; } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } } return(DVR); }
/// <summary> /// Purpose is to create a client given a Client Code and Client Folder. /// </summary> /// <param name="clientCode">Unique Client Code</param> /// <param name="clientFolder">Unique Client Folder</param> /// <returns></returns> public DataValidatorReturn Create(string activityTypeShortDesc, string activityTypeLongDesc) { DVR = MethodHelper.IsParameterEmpty("Activity Type", activityTypeShortDesc); if (DVR.IsValid == false) { return(DVR); } DVR = MethodHelper.IsParameterEmpty("Activity Type Description", activityTypeLongDesc); if (DVR.IsValid == false) { return(DVR); } if (Find(activityTypeShortDesc).ItemFound) { DVR.IsValid = false; DVR.ReturnText = activityTypeShortDesc + " already exists."; DVR.ItemFound = true; return(DVR); } using (var context = new WorkOrderLogEntities()) { ActivityType activityType = new ActivityType() { ShortDescription = activityTypeShortDesc, LongDescription = activityTypeLongDesc }; try { context.ActivityTypes.Add(activityType); context.SaveChanges(); DVR.IsValid = true; DVR.ReturnText = "Activity Type: " + activityTypeShortDesc + " Added to the Database."; DVR.ReturnType = activityType; } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } } return(DVR); }
public DataValidatorReturn Find(int activityTypeID) { DVR = MethodHelper.IsGreaterThanZero("Activity Type ID", activityTypeID); if (DVR.IsValid == false) { return(DVR); } BO_ActivityType bo_ActivityType = new BO_ActivityType(); DVR = bo_ActivityType.Find(activityTypeID); if (DVR.ItemFound == false) { return(DVR); } try { List <SourceScriptHdr> sourceScriptHdrs = new List <SourceScriptHdr>(); using (var context = new WorkOrderLogEntities()) { sourceScriptHdrs = context.SourceScriptHdrs.Include(x => x.SourceScriptDtls.Select(c => c.Client)).Where(x => x.ActivityTypeID == activityTypeID).ToList(); } DVR.ItemFound = sourceScriptHdrs.Any(); DVR.IsValid = true; DVR.ReturnType = sourceScriptHdrs.FirstOrDefault(); if (DVR.ItemFound) { DVR.ReturnText = sourceScriptHdrs.Count().ToString() + " Source Script Headers Found."; DVR.ReturnType = sourceScriptHdrs.FirstOrDefault(); } else { DVR.ReturnText = "Source Script Header Not Found."; } } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } return(DVR); }
// Purpose: Find a client given a client Code. public DataValidatorReturn Find(string clientCode) { DVR = MethodHelper.IsParameterEmpty("ClientCode", clientCode); if (DVR.IsValid == false) { return(DVR); } try { List <Client> clients = new List <Client>(); using (var context = new WorkOrderLogEntities()) { clients = context.Clients.Where(x => x.ClientCode == clientCode).ToList(); } DVR.ItemFound = clients.Any(); DVR.IsValid = true; DVR.ReturnType = clients.FirstOrDefault(); if (DVR.ItemFound) { DVR.ReturnText = clients.Count().ToString() + " Client Found."; DVR.ReturnType = clients.FirstOrDefault(); } else { DVR.ReturnText = clientCode + " Not Found."; } } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } return(DVR); }
public DataValidatorReturn Find(string activityTypeShortDesc) { DVR = MethodHelper.IsParameterEmpty("Activity Type", activityTypeShortDesc); if (DVR.IsValid == false) { return(DVR); } try { List <ActivityType> activityTypes = new List <ActivityType>(); using (var context = new WorkOrderLogEntities()) { activityTypes = context.ActivityTypes.Where(x => x.ShortDescription == activityTypeShortDesc).ToList(); } DVR.ItemFound = activityTypes.Any(); DVR.IsValid = true; DVR.ReturnType = activityTypes.FirstOrDefault(); if (DVR.ItemFound) { DVR.ReturnText = activityTypes.Count().ToString() + " Activity Type Found."; DVR.ReturnType = activityTypes.FirstOrDefault(); } else { DVR.ReturnText = "Activity Type Not Found."; } } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } return(DVR); }
public DataValidatorReturn Find(int workOrderID) { DVR = MethodHelper.IsGreaterThanZero("Work Order Number", workOrderID); if (DVR.IsValid == false) { return(DVR); } try { List <WorkOrderHeader> workOrderHeaders = new List <WorkOrderHeader>(); using (var context = new WorkOrderLogEntities()) { workOrderHeaders = context.WorkOrderHeaders.Include(x => x.Client).Where(x => x.WOHdrID == workOrderID).ToList(); } DVR.ItemFound = workOrderHeaders.Any(); DVR.IsValid = true; DVR.ReturnType = workOrderHeaders.FirstOrDefault(); if (DVR.ItemFound) { DVR.ReturnText = workOrderHeaders.Count().ToString() + " Work Order Found."; DVR.ReturnType = workOrderHeaders.FirstOrDefault(); } else { DVR.ReturnText = "Work Order Not Found."; } } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } return(DVR); }
public DataValidatorReturn Find(int activityID) { DVR = MethodHelper.IsGreaterThanZero("Activity", activityID); if (DVR.IsValid == false) { return(DVR); } try { List <Activity> activities = new List <Activity>(); using (var context = new WorkOrderLogEntities()) { activities = context.Activities.Where(x => x.ActivityID == activityID).ToList(); } DVR.ItemFound = activities.Any(); DVR.IsValid = true; DVR.ReturnType = activities.FirstOrDefault(); if (DVR.ItemFound) { DVR.ReturnText = activities.Count().ToString() + " Activity Found."; DVR.ReturnType = activities.FirstOrDefault(); } else { DVR.ReturnText = "Activity Not Found."; } } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } return(DVR); }
public DataValidatorReturn Delete(int activityTypeID) { DVR = MethodHelper.IsGreaterThanZero("Activity Type", activityTypeID); if (DVR.IsValid == false) { return(DVR); } DataValidatorReturn dvr = new DataValidatorReturn(); dvr = Find(activityTypeID); if (dvr.ItemFound == false) { DVR.IsValid = false; DVR.ReturnText = activityTypeID + " not found."; DVR.ItemFound = false; return(DVR); } using (var context = new WorkOrderLogEntities()) { try { int numWorkOrderDetails = 0; int numActivities = 0; int currentActivityId = 0; //Delete foreign relationships etc. //Get the activities. var activities = context.Activities.Where(x => x.ActivityTypeID == activityTypeID).ToList(); if (activities.Any()) { numActivities = activities.Count(); for (int i = 0; i < numActivities; i++) { currentActivityId = activities[i].ActivityID; List <WorkOrderDetail> workOrderDetails = context.WorkOrderDetails.Where(x => x.ActivityID == currentActivityId).ToList(); if (workOrderDetails.Any()) { numWorkOrderDetails = workOrderDetails.Count(); for (int j = 0; j < numWorkOrderDetails; j++) { WorkOrderDetail workOrderDetail = workOrderDetails[j]; context.WorkOrderDetails.Remove(workOrderDetail); } } Activity activity = activities[i]; context.Activities.Remove(activity); } } ActivityType activityType = context.ActivityTypes.Where(x => x.ActivityTypeID == activityTypeID).FirstOrDefault(); context.ActivityTypes.Remove(activityType); context.SaveChanges(); DVR.IsValid = true; DVR.ReturnText = activityType.ShortDescription + " Removed Successfully." + Environment.NewLine + numActivities.ToString() + " Activities Removed successfully." + Environment.NewLine + numWorkOrderDetails + " Removed Successfully."; } catch (Exception exception) { DVR.IsValid = false; DVR.ErrorText = exception.Message; } } return(DVR); }
public DataValidatorReturn Create(int workOrderID, int itemNumber, int activityID) { WorkOrderHeader workOrderHeader = null; DVR = MethodHelper.IsGreaterThanZero("Work Order Number", workOrderID); if (DVR.IsValid == false) { return(DVR); } DVR = MethodHelper.IsGreaterThanZero("Item Number", itemNumber); if (DVR.IsValid == false) { return(DVR); } DVR = MethodHelper.IsGreaterThanZero("Activity ID", activityID); if (DVR.IsValid == false) { return(DVR); } if (Find(workOrderID, itemNumber, activityID).ItemFound) { DVR.IsValid = false; DVR.ReturnText = "Work Order Detail # " + workOrderID.ToString() + " already exists."; DVR.ItemFound = true; return(DVR); } BO_WorkOrderHeader bo_WorkOrderHeader = new BO_WorkOrderHeader(); DVR = bo_WorkOrderHeader.Find(workOrderID); if (DVR.ItemFound == false) { DVR.IsValid = false; DVR.ReturnText = "Work Order Header # " + workOrderID.ToString() + " doesn't exist."; DVR.ItemFound = true; return(DVR); } else { workOrderHeader = DVR.ReturnType as WorkOrderHeader; } using (var context = new WorkOrderLogEntities()) { // Find the work Order Header here. WorkOrderDetail workOrderDetail = new WorkOrderDetail() { WOHdrID = workOrderID, ItemNumber = itemNumber, ActivityID = activityID }; try { int activityTypeID = 2; context.WorkOrderDetails.Add(workOrderDetail); context.SaveChanges(); //Once we have created a work order detail need to look for the //Activity using the activity Id, and then get the activityTypeId //Go to the sourcescripthdr table and get the sourcescripthdrid //and use the info from the sourcescriptdtl table to create //WorkOrderDtlScript records also need to create these actual files //by retrieving the source items and pasting to the new files. BO_SourceScriptHdr bo_SourceScriptHdr = new BO_SourceScriptHdr(); DataValidatorReturn dataValidatorReturn = bo_SourceScriptHdr.Find(activityTypeID); if (dataValidatorReturn.ItemFound) { var sourceScriptHdr = dataValidatorReturn.ReturnType as SourceScriptHdr; var sourceScriptDtls = sourceScriptHdr.SourceScriptDtls; if (sourceScriptDtls.Any()) { string sourceFileFullPath = string.Empty; string sourceFile = string.Empty; string sourceClientCode = string.Empty; string destFile = string.Empty; string destClientCode = string.Empty; string destFileFullPath = string.Empty; string destFolder = string.Empty; string sourceFileContents = string.Empty; string destFileContents = string.Empty; foreach (SourceScriptDtl sourceScriptDtl in sourceScriptDtls) { // Set the source File. sourceFile = sourceScriptDtl.SourceFile; sourceClientCode = sourceScriptDtl.ClientCode; sourceFileFullPath = Path.Combine(sourceScriptDtl.Client.ClientFolder, sourceScriptDtl.SourceFile); destClientCode = workOrderHeader.ClientCode; destFile = sourceFile.Replace(sourceClientCode, destClientCode); destFolder = workOrderHeader.Client.ClientFolder; destFileFullPath = Path.Combine(destFolder, destFile); // Logic change instead of copying, replace text required sourceFileContents = File.ReadAllText(sourceFileFullPath); destFileContents = sourceFileContents.Replace(sourceClientCode, destClientCode); destFileContents = destFileContents.Replace("0", workOrderHeader.WOHdrID.ToString()); File.WriteAllText(destFileFullPath, destFileContents); //Create WorkOrderDetailScripts foreach script created. BO_WorkOrderDtlScripts bo_WorkOrderDtlScripts = new BO_WorkOrderDtlScripts(); bo_WorkOrderDtlScripts.Create(workOrderDetail.WODtlId, destFile); } context.SaveChanges(); } } DVR.IsValid = true; DVR.ReturnText = "Work Order Detail #" + workOrderID.ToString() + " Added to the Database."; DVR.ReturnType = workOrderDetail; } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } } return(DVR); }
public DataValidatorReturn Find(int workOrderID, int itemNumber, int activityID) { DVR = MethodHelper.IsGreaterThanZero("Work Order Number", workOrderID); if (DVR.IsValid == false) { return(DVR); } DVR = MethodHelper.IsGreaterThanZero("Item Number", itemNumber); if (DVR.IsValid == false) { return(DVR); } DVR = MethodHelper.IsGreaterThanZero("Activity ID", activityID); if (DVR.IsValid == false) { return(DVR); } BO_WorkOrderHeader bO_WorkOrderHeader = new BO_WorkOrderHeader(); DVR = bO_WorkOrderHeader.Find(workOrderID); if (DVR.ItemFound == false) { return(DVR); } BO_Activity bO_Activity = new BO_Activity(); DVR = bO_Activity.Find(activityID); if (DVR.ItemFound == false) { return(DVR); } try { List <WorkOrderDetail> workOrderDetails = new List <WorkOrderDetail>(); using (var context = new WorkOrderLogEntities()) { workOrderDetails = context.WorkOrderDetails.Where(x => x.WOHdrID == workOrderID && x.ActivityID == activityID && x.ItemNumber == itemNumber).ToList(); } DVR.ItemFound = workOrderDetails.Any(); DVR.IsValid = true; DVR.ReturnType = workOrderDetails.FirstOrDefault(); if (DVR.ItemFound) { DVR.ReturnText = workOrderDetails.Count().ToString() + " Work Order Details Found."; DVR.ReturnType = workOrderDetails.FirstOrDefault(); } else { DVR.ReturnText = "Work Order Detail Not Found."; } } catch (Exception exception) { DVR.IsValid = false; DVR.ReturnText = exception.Message; } return(DVR); }