/// <summary> /// Get VFR Server Information /// </summary> /// <returns></returns> static public GlobalVars.ResultsVFR GetVFRInfoByJobID(int jobID) { GlobalVars.VFR vfr = new GlobalVars.VFR(); GlobalVars.ResultsVFR resultVFR = new GlobalVars.ResultsVFR() { ReturnCode = 0, Message = "", ReturnValue = vfr, RecordsCount = 0, HttpStatusCode = "" }; try { logger.Trace("Entering into GetVFRInfoByJobID Method ..."); using (ScanningDBContext DB = new ScanningDBContext()) { var results = DB.Vfr.FirstOrDefault(x => x.JobId == jobID); if (results != null) { resultVFR.RecordsCount = 1; vfr.CADIUrl = results.Cadiurl; vfr.CaptureTemplate = results.CaptureTemplate; vfr.InstanceName = results.InstanceName; vfr.JobID = results.JobId; vfr.SettingID = results.SettingId; vfr.Password = results.Password; vfr.UserName = results.UserName; vfr.RepositoryName = results.RepositoryName; vfr.QueryField = results.QueryField; } else { //There is no record in the database } } resultVFR.ReturnValue = vfr; resultVFR.Message = "GetVFRInfoByJobID transaction completed successfully. Number of records found: " + resultVFR.RecordsCount; logger.Debug(resultVFR.Message); } catch (Exception e) { logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException); resultVFR.ReturnCode = -2; resultVFR.Message = e.Message; var baseException = e.GetBaseException(); resultVFR.Exception = baseException.ToString(); } logger.Trace("Leaving GetVFRInfoByJobID Method ..."); return(resultVFR); }
public ActionResult UpdateVFRInfo([FromBody] string vfrJS) { var watch = System.Diagnostics.Stopwatch.StartNew(); GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric() { Message = "", ReturnCode = 0, //ReturnValue = "" }; try { if (vfrJS == null) { Response.StatusCode = (int)HttpStatusCode.BadRequest; result.ReturnCode = -1; result.Message = "Missing argument vfrJS"; logger.Warn("UpdateVFRInfo API Request ends with an Error."); logger.Warn(result.Message); } else { GlobalVars.VFR vfr = JsonConvert.DeserializeObject <GlobalVars.VFR>(vfrJS); logger.Info("UpdateVFRInfo API Request."); if (vfr.JobID != 0) { logger.Debug("Parameter:" + JsonConvert.SerializeObject(vfr, Formatting.Indented)); result = SQLFunctionsVFR.UpdateVFRInfo(vfr); switch (result.ReturnCode) { case 0: logger.Info("UpdateVFRInfo API Request was executed Successfully."); Response.StatusCode = (int)HttpStatusCode.OK; break; case -1: logger.Info("UpdateVFRInfo API Request ends with a warning."); Response.StatusCode = (int)HttpStatusCode.OK; break; case -2: Response.StatusCode = (int)HttpStatusCode.InternalServerError; logger.Fatal("UpdateVFRInfo API Request ends with a Fatal Error."); logger.Debug("Returned value:" + JsonConvert.SerializeObject(result, Formatting.Indented)); Response.StatusCode = (int)HttpStatusCode.InternalServerError; break; } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; result.ReturnCode = -1; result.Message = "Job ID value is not valid."; logger.Warn("UpdateVFRInfo API Request ends with an Error."); logger.Warn(result.Message); } } } catch (Exception e) { logger.Fatal("UpdateVFRInfo API Request ends with a Fatal Error."); result.ReturnCode = -2; result.Message = e.Message; var baseException = e.GetBaseException(); result.Exception = baseException.ToString(); logger.Fatal("Returned value:" + JsonConvert.SerializeObject(result, Formatting.Indented)); Response.StatusCode = (int)HttpStatusCode.InternalServerError; } Response.ContentType = "application/json"; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; elapsedMs = elapsedMs / 1000; result.ElapsedTime = elapsedMs.ToString(); result.HttpStatusCode = Response.StatusCode.ToString(); var messaje = JsonConvert.SerializeObject(result, Formatting.Indented); logger.Info("Leaving UpdateVFRInfo API"); //return Json(messaje); return(Content(messaje)); }
/// <summary> /// The Update Method creates a new records if it does not exist /// </summary> /// <returns></returns> static public GlobalVars.ResultGeneric UpdateVFRInfo(GlobalVars.VFR vfr) { GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric() { ReturnCode = 0, Message = "", RecordsCount = 0, HttpStatusCode = "" }; try { logger.Trace("Entering into UpdateVFRInfo Method ..."); using (ScanningDBContext DB = new ScanningDBContext()) { // Customer Names must be unique in the Database. The Name could be change but it must be unique Vfr Matching_Result = DB.Vfr.FirstOrDefault(x => x.JobId == vfr.JobID); Vfr record = new Vfr(); record.Cadiurl = vfr.CADIUrl; record.CaptureTemplate = vfr.CaptureTemplate; record.InstanceName = vfr.InstanceName; record.JobId = vfr.JobID; //record.SettingId = vfr.SettingID; record.Password = vfr.Password; record.UserName = vfr.UserName; record.RepositoryName = vfr.RepositoryName; record.QueryField = vfr.QueryField; if (Matching_Result == null) { DB.Vfr.Add(record); DB.SaveChanges(); result.Message = "There was not information associated to an VFR Server, so new records was created successfully."; } else { // Means --> table has a record and it will be updated Matching_Result.Cadiurl = vfr.CADIUrl; Matching_Result.CaptureTemplate = vfr.CaptureTemplate; Matching_Result.InstanceName = vfr.InstanceName; Matching_Result.JobId = vfr.JobID; //Matching_Result.SettingId = vfr.SettingID; Matching_Result.Password = vfr.Password; Matching_Result.UserName = vfr.UserName; Matching_Result.RepositoryName = vfr.RepositoryName; Matching_Result.QueryField = vfr.QueryField; DB.SaveChanges(); result.Message = "VFR Inforation was updated successfully."; } } logger.Debug(result.Message); } catch (Exception e) { logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException); result.ReturnCode = -2; result.Message = e.Message; var baseException = e.GetBaseException(); result.Exception = baseException.ToString(); } logger.Trace("Leaving UpdateVFRInfo Method ..."); return(result); }