public int AddSys_ParamsCheckPrevious(Sys_Param sysParam) { try { if (sysParam == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Sys_Param.Any()) { return(-3); } var processedParams = db.Sys_Param.Add(sysParam); db.SaveChanges(); return(processedParams.Sys_ParamId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult AddParam(Sys_Param plParam) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (!ModelState.IsValid) { ViewBag.StatusMessage = "Please supply all the required input and try again"; ViewBag.Code = -1; return(View("DBBackup", plParam)); } var wx = ValidateControl(plParam); if (wx.Code < 1) { ViewBag.StatusMessage = "Validation failed. Please supply all the required input and try again"; ViewBag.Code = -1; return(View("DBBackup", plParam)); } var k = new Sys_ParamsServices().AddSys_ParamsCheckPrevious(plParam); if (k < 1) { if (k == -3) { ViewBag.StatusMessage = "An unknown error was encountered. Please try again."; ViewBag.Code = -1; return(View("DBBackup", plParam)); } ViewBag.StatusMessage = "Process failed. Please try again."; ViewBag.Code = -1; return(View("DBBackup", plParam)); } ViewBag.StatusMessage = "Database configuration was successfully added"; ViewBag.Code = 5; return(View("DBBackup", plParam)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); ViewBag.StatusMessage = "An unknown error was encountered. Please try again."; ViewBag.Code = -1; return(View("DBBackup", plParam)); } }
private static GenericValidator ValidateControl(Sys_Param model) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(model.ServerLoginName.Trim())) { gVal.Error = "Please Provide Server Login Name."; gVal.Code = 0; return(gVal); } if (string.IsNullOrEmpty(model.ServerLoginPassword.Trim())) { gVal.Error = "Please Provide Server Login Password."; gVal.Code = 0; return(gVal); } if (string.IsNullOrEmpty(model.DBName.Trim())) { gVal.Error = "Please Provide Database Name."; gVal.Code = 0; return(gVal); } if (string.IsNullOrEmpty(model.ServerName.Trim())) { gVal.Error = "Please Provide Server Name."; gVal.Code = 0; return(gVal); } gVal.Code = 1; return(gVal); } catch (Exception) { gVal.Error = "Process validation failed. Please supply all required fields and try again."; gVal.Code = 0; return(gVal); } }
public int UpdateSys_Params(Sys_Param sys_Param) { try { if (sys_Param == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { db.Sys_Param.Attach(sys_Param); db.Entry(sys_Param).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditParam(Sys_Param plParam) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (Session["_param"] == null) { ViewBag.StatusMessage = "Session has expired"; ViewBag.Code = -1; return(View("DBBackup", plParam)); } var oldParam = Session["_param"] as Sys_Param; if (oldParam == null || oldParam.Sys_ParamId < 1) { ViewBag.StatusMessage = "Session has expired"; ViewBag.Code = -1; return(View("DBBackup", plParam)); } if (!ModelState.IsValid) { ViewBag.StatusMessage = "Please supply all required fields and try again"; ViewBag.Code = -1; return(View("DBBackup", plParam)); } var wx = ValidateControl(plParam); if (wx.Code < 1) { ViewBag.StatusMessage = wx.Error; ViewBag.Code = -1; return(View("DBBackup", plParam)); } oldParam.ServerName = plParam.ServerName; oldParam.ServerLoginPassword = plParam.ServerLoginPassword; oldParam.ServerLoginName = plParam.ServerLoginName; oldParam.DBName = plParam.DBName; var k = new Sys_ParamsServices().UpdateSys_Params(oldParam); if (k < 1) { ViewBag.StatusMessage = "Process Failed! Please contact the Admin or try again later"; ViewBag.Code = -1; return(View("DBBackup", plParam)); } ViewBag.StatusMessage = "Database configuration was successfully updated"; ViewBag.Code = 5; return(View("DBBackup", plParam)); } catch (Exception) { //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); ViewBag.StatusMessage = "An unknown error was encountered. Request could not be serviced. Please try again later."; ViewBag.Code = -1; return(View("DBBackup", plParam)); } }