public Tuple <string, int> CheckTens(string FinalValue, int Identifier, string[] strInputnumber, int j, string strNumeralSystem) { try { if (FinalValue != "Error in Conversion") { MyLogger.GetInstance().Info("Entering the CheckTens Method"); var tuple = new Tuple <string, int>(FinalValue, Identifier); if (j == Identifier && strInputnumber[j] == "1") { FinalValue = assign.Assigncombovalue(FinalValue, strInputnumber[j + 1]); Identifier = SetIDentifier(Identifier, strNumeralSystem); } else if (j == Identifier && strInputnumber[j] != "1") { FinalValue = assign.Assigndoublevalue(FinalValue, strInputnumber[j]); Identifier = SetIDentifier(Identifier, strNumeralSystem); } } return(Tuple.Create(FinalValue, Identifier)); } catch (Exception Ex) { MyLogger.GetInstance().Error("Error at " + MethodBase.GetCurrentMethod() + " with the error message " + Ex.Message); return(Tuple.Create("Error in Conversion", Identifier)); } finally { MyLogger.GetInstance().Info("Exiting the CheckTens Method"); } }
public ActionResult Edit(WrapperUpdateProject model) { ActionResponse ar = new ActionResponse(); string output = ""; MyLogger.GetInstance().Info("Updating Gate Info .." + model.gateVersion.gvProjectId); if (ModelState.IsValid) { SQLManager pm = new SQLManager(); ar = pm.UpdateGateInfo(model); if (!ar.IsSuccess) { return(RedirectToAction("ErrorView", "Project", new { msg = ar.ErrorMsg })); } else { output = "gate info updated successfully"; MyLogger.GetInstance().Info("Updated gate info successfully.." + model.gateVersion.gvProjectId); } } return(Json(output, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveProjectInfo(WrapperViewEditProject we) { bool result = false; msg = ""; MyLogger.GetInstance().Info("Udating Project Info"); if (ModelState.IsValid) { SQLManager pm = new SQLManager(); result = pm.SaveProjectInfo(we); if (result == false) { msg = "Error updating project" + we.project.name; MyLogger.GetInstance().Error(msg); return(RedirectToAction("ErrorView", "Project", new { message = msg })); } else { msg = "successfully updated project info " + we.project.name; MyLogger.GetInstance().Info(msg); } } // var output = "yahoo"; return(Json(msg, JsonRequestBehavior.AllowGet)); }
public Service AddService(Service service) { try { if (service != null) { if (service.Id == 0) { _dbContext.services.Add(service); _dbContext.SaveChanges(); MyLogger.GetInstance().Info(service.Name + " added successfully"); return(service); } else { _dbContext.Entry(service).State = EntityState.Modified; _dbContext.SaveChanges(); MyLogger.GetInstance().Info(service.Name + " updated successfully"); return(service); } } else { return(null); } } catch (Exception ex) { MyLogger.GetInstance().Info(ex.Message); return(null); } }
public ActionResult Login(UserModel user) { //put an item in the log file stateting you've entered this method MyLogger.GetInstance().Info(""); MyLogger.GetInstance().Info("Entering the login controller. Login method"); try { //Call the Security Business Service Authenticate() method from the Login() method //and save the results of the method call in a local method variable SecurityService securityService = new SecurityService(); Boolean success = securityService.Authenticate(user); if (success) { MyLogger.GetInstance().Info("Exiting the login controller. Login Success!"); return(View("LoginSuccess", user)); //"<h2>Login Success</h2><p>User: "******" Pass: "******" is correct!</p>"; } else { MyLogger.GetInstance().Info("Exiting the login controller. Login Failure"); return(View("LoginFailed")); //"<h1>Fail!</h1>"; } } catch (Exception e) { MyLogger.GetInstance().Error("Exception!" + e.Message); return(Content("Exception in login" + e.Message)); } }
public string SaveData(string strNumber, string strNumberText) { try { MyLogger.GetInstance().Info("Entering the SaveData Method with the values strNumber = " + strNumber + " strNumberText = " + strNumberText); if (strNumber != "" && strNumberText != "") { DBLogics Save = new DBLogics(); int intResult = Save.SaveData(strNumber, strNumberText); if (intResult != 0) { strResult = "Data Saved Successfully"; } else { strResult = "Unable to Save the Entered Number " + strNumber; } } return(strResult); } catch (Exception Ex) { MyLogger.GetInstance().Error("Error at " + MethodBase.GetCurrentMethod() + " with the error message " + Ex.Message); return(strResult = "Unable to Save Data"); } finally { MyLogger.GetInstance().Info("Exiting the ReturnWordValue Method"); } }
public ActionResult Login(UserModel user) { MyLogger.GetInstance().Info("Entering the login controller. Login Method"); try { if (!ModelState.IsValid) { return(View("Login")); } SecurityService ss = new SecurityService(); Boolean success = ss.Authenticate(user); if (success) { MyLogger.GetInstance().Info("Exiting LoginController.Login() Login passed!"); return(View("LoginPassed")); } else { MyLogger.GetInstance().Info("Exiting LoginController.Login() Login Failed!"); return(View("LoginFailed", user)); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception! " + e.Message); return(Content("Exception in login" + e.Message)); } }
public ActionResult searchVerse(BibleVerse bibleVerse) { Debug.WriteLine(bibleVerse.ChapterNumber); //put an item in the log file stateting you've entered this method MyLogger.GetInstance().Info(""); MyLogger.GetInstance().Info("Entering the BibleController. searchVerse() method"); try { //Call the Security Business Service findVerse() method from the searchVerse() method //and save the results of the method call in a local variable: returnedVerse SecurityService securityService = new SecurityService(); BibleVerse returnedVerse = securityService.findVerse(bibleVerse); Debug.WriteLine("controller return: " + returnedVerse.VerseText); if (returnedVerse.VerseText == "") { MyLogger.GetInstance().Info("Exiting the BibleController. searchVerse Failure"); return(View("SearchVerseFail")); } else { MyLogger.GetInstance().Info("Exiting the searchVerse() in BibleController. searchVerse Success!"); return(View("SearchVerseResult", returnedVerse)); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception!" + e.Message); return(Content("Exception in searchVerse" + e.Message)); } }
public ActionResult Login(UserModel model) { MyLogger.GetInstance().Info("Entering the login controller using login ActionResult."); try { SecurityService security = new SecurityService(); model = new UserModel(); // Validate the Form POST if (!ModelState.IsValid) { return(View("Login")); } bool check = security.Authenticate(model); if (check == true) { MyLogger.GetInstance().Info("Exit login controller. Login successful."); return(View("LoginPassed")); } else { MyLogger.GetInstance().Info("Exit login controller. Login failure."); return(View("LoginFailed")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception! " + e.Message); return(Content("Exception in login" + e.Message)); } }
public ActionResult FindVerse(BibleVerseModel verseModel) { MyLogger.GetInstance().Info("Entering BibleController.FindVerse()"); //create an instance of the security service to access the search method SecurityService securityService = new SecurityService(); //set the results to a new bibleversemodel BibleVerseModel verseFound = new BibleVerseModel(securityService.Search(verseModel).Testament, securityService.Search(verseModel).Book, securityService.Search(verseModel).ChapterNumber, securityService.Search(verseModel).VerseNumber, securityService.Search(verseModel).VerseText); try { //check the results and return the appropriate page if (securityService.Search(verseModel) != null) { MyLogger.GetInstance().Info("Exiting BibleController.FindVerse() with successful search of a certain verse."); return(View("FindVerseSuccess", verseFound)); } else { MyLogger.GetInstance().Info("Exiting BibleController.FindVerse() with failed search of a certain verse."); return(View("FindVerseFailure")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception BibleController.FindVerse()", e.Message); string errMessage = e.Message; return(View("Error", errMessage)); } }
public ActionResult addVerse(BibleVerse bibleVerse) { //put an item in the log file stateting you've entered this method MyLogger.GetInstance().Info(""); MyLogger.GetInstance().Info("Entering the BibleController. addVerse() method"); try { //Call the Security Business Service createVerse() method from the addVerse() method //and save the results of the method call in a local variable: success SecurityService securityService = new SecurityService(); Boolean success = securityService.createVerse(bibleVerse); if (success) { MyLogger.GetInstance().Info("Exiting the addVerse() in BibleController. Add Success!"); return(View("AddVerseSuccess")); } else { MyLogger.GetInstance().Info("Exiting the BibleController. Login Failure"); return(View("AddVerseFail")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception!" + e.Message); return(Content("Exception in addVerse" + e.Message)); } }
public ActionResult EnterVerse(BibleVerseModel verseModel) { MyLogger.GetInstance().Info("Entering BibleController.EnterVerse()"); //create an instance of the security service to access the create method SecurityService securityService = new SecurityService(); //return the results to a bool to show if the creation was successful or not Boolean success = securityService.Create(verseModel); try { //check the results and return the appropriate page if (success) { MyLogger.GetInstance().Info("Exiting BibleController.EnterVerse() with successful creation of a new verse."); return(View("NewVerseSuccess", verseModel)); } else { MyLogger.GetInstance().Info("Exiting BibleController.EnterVerse() with failed creation of a new verse."); return(View("NewVerseFailure")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception BibleController.EnterVerse()", e.Message); string errMessage = e.Message; return(View("Error", errMessage)); } }
public IActionResult Logout() { MyLogger.GetInstance().Info("Processing a logout attempt for - " + HttpContext.Session.GetString("username")); //Remove all sessions that hold credentials //HttpContext.Session.SetString("username", String.Empty); //HttpContext.Session.SetInt32("userID", 0); //Remove all sessions that hold credentials HttpContext.Session.Remove("username"); HttpContext.Session.Remove("userID"); if (!String.IsNullOrEmpty(HttpContext.Session.GetString("username")) && (HttpContext.Session.GetString("userID") != null)) { logger.Warning("Failre removal of session - " + String.IsNullOrEmpty(HttpContext.Session.GetString("username")) + " at logout"); } else { logger.Info("Sucess removal of session at logout"); } return(View("Index")); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); MyLogger.GetInstance().Info("Product Id : " + id + " updated."); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { MyLogger.GetInstance().Error("Product does not exists with ID : " + id); return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Login(LoginFormViewModel user) { try { HttpResponseMessage responseGet = GlobalVariables.WebApiClient.GetAsync("User").Result; var userList = responseGet.Content.ReadAsAsync <IEnumerable <User> >().Result; var loginUser = userList.Where(u => u.Email == user.Email).FirstOrDefault(); if (loginUser == null) { ModelState.AddModelError("Email", "User Does not exist"); return(View()); } else { if (loginUser.Password != user.Password) { ModelState.AddModelError("Password", "Incorrect Password"); return(View()); } else { Session["username"] = loginUser.Username; MyLogger.GetInstance().Info("User Logged in by username : "******"successfull login"); return(RedirectToAction("Index")); } } } catch (Exception ex) { MyLogger.GetInstance().Error("Exception at user Login : "******"Index")); } }
public ActionResult Add(Application app, string saveasnew) { MyLogger.GetInstance().Info("Updating Application"); List <Application> applist = null; if (ModelState.IsValid) { DbManagerFactory dbm = new DbManagerFactory(ProjectBaseClass.dbType()); IProject ip = dbm.GetDbManager(); ActionResponse ar = new ActionResponse(); ar = ip.UpdateApplication(app, saveasnew); if (!ar.IsSuccess) { //return RedirectToAction("ErrorView", "Project", new { message = ar.ErrorMsg }); } applist = ar.obj; } return(PartialView("~/Views/Application/ShowApps.cshtml", applist)); // return Json(app, JsonRequestBehavior.AllowGet); }
public void SetValues(int arraylength) { MyLogger.GetInstance().Info("Entering the SetValues Method with the array length" + arraylength); try { if ((arraylength - 3) % 2 == 1) { singleIdentifier = 1; valueIdentifier = 0; } if ((arraylength - 3) % 2 == 0) { singleIdentifier = 0; valueIdentifier = 1; } hundredIdentifier = arraylength - 3; MyLogger.GetInstance().Info("Exiting the SetValues Method with the array length" + arraylength); } catch (Exception Ex) { MyLogger.GetInstance().Error("Error at " + MethodBase.GetCurrentMethod() + " with the error message " + Ex.Message); } }
//Make sure verse does not all ready exisit. public bool CheckExisting() { try { MyLogger.GetInstance().Info("Check if verse already exists! CheckExisting()"); string query = "SELECT * FROM dbo.Verse WHERE Book=@book AND Verse=@verse AND Text=@text"; SqlCommand command = new SqlCommand(query, connection); command.Parameters.Add("@book", SqlDbType.NVarChar, 50).Value = book; command.Parameters.Add("@verse", SqlDbType.Int).Value = verse; command.Parameters.Add("@text", SqlDbType.NVarChar).Value = text; connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { connection.Close(); MyLogger.GetInstance().Info("The verse already exists in our App!"); return(false); } else { connection.Close(); MyLogger.GetInstance().Info("This verse is not in the App yet!"); return(true); } } catch (SqlException e) { MyLogger.GetInstance().Info("There was an error trying to add: " + e.ToString()); throw e; } }
public string ReturnWordValue(string strnumber) { string[] strCompletetext = strnumber.Split('.'); try { MyLogger.GetInstance().Info("Entering the ReturnWordValue Method with the input " + strnumber); if (strnumber.Contains('.')) { strDecimalNumber = strCompletetext[1].ToString(); strdecimalNumber = check.ConvertToArray(strDecimalNumber); } strnumber = strCompletetext[0].ToString(); strnumber = check.Removezeroes(strnumber); String[] strInputnumber = check.ConvertToArray(strnumber); SetValues(strInputnumber.Length); Dictionary <int, string> NumeralSystem = num.ReturnNumeralValue("Indian"); WorkNumberValue(strInputnumber, strdecimalNumber, NumeralSystem); return(FinalValue); } catch (Exception Ex) { MyLogger.GetInstance().Error("Error at " + MethodBase.GetCurrentMethod() + "/n Value Provided to this method " + strnumber + "with the error message " + Ex.Message); return("Error in Conversion"); } finally { MyLogger.GetInstance().Info("Exiting the ReturnWordValue Method"); } }
public static string[] ClearText() { Regex htmlSymbols = new Regex(@"&..*"); string[] charsToRemove = new string[] { "@", "+", "=", "{", "}", "*", "/", "<", ">", "%", "^", "~" }; char[] separators = new char[] { ' ', ',', '.', '!', '?', '"', ';', ':', '[', ']', '(', ')', '\n', '\r', '\t', '-', '—' }; MyLogger.GetInstance().Info("Search a text"); string htmlNodes = site.DocumentNode.SelectSingleNode("/html/body").InnerText.Trim().Replace(" ", "").Replace("-", ""); MyLogger.GetInstance().Info("Delete HTML symbols"); string deletingHTMLSymbols = htmlSymbols.Replace(htmlNodes.ToString(), ""); // delete html symbols MyLogger.GetInstance().Info("Delete numbers"); string deletingNumbers = new string(deletingHTMLSymbols.Where(c => c != '-' && (c <'0' || c> '9')).ToArray()); // delete numbers MyLogger.GetInstance().Info("Escape words"); string escapedWords = deletingNumbers.Replace("'", "``"); MyLogger.GetInstance().Info("Delete symbols"); foreach (string c in charsToRemove) { escapedWords = escapedWords.Replace(c, string.Empty); } MyLogger.GetInstance().Info("Split string"); string[] words = escapedWords.Split(separators, StringSplitOptions.RemoveEmptyEntries); return(words); }
public int SaveData(string strNumber, string strNumbertext) { SqlConnection sqlCon = new SqlConnection(strConnection); try { MyLogger.GetInstance().Info("Entering the SaveData Method"); SqlCommand cmd = new SqlCommand("InsertData", sqlCon); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Number", SqlDbType.Float).Value = strNumber; cmd.Parameters.Add("@NumberText", SqlDbType.VarChar).Value = strNumbertext; sqlCon.Open(); int intResult = cmd.ExecuteNonQuery(); sqlCon.Close(); return(intResult); } catch (Exception Ex) { sqlCon.Close(); MyLogger.GetInstance().Error("Error at " + MethodBase.GetCurrentMethod() + " with the error message " + Ex.Message); return(0); } finally { sqlCon.Close(); MyLogger.GetInstance().Info("Exiting the SaveData Method"); } }
public string GetUsers() { //get the default memory cache var cache = MemoryCache.Default; //get users from the cache and if users do not exist in the cache, put them in the cache List <UserModel> users = cache.Get("Users") as List <UserModel>; if (users == null) { MyLogger.GetInstance().Info("Creating Users and putting them into the cache"); //create a list of users users = new List <UserModel>(); users.Add(new UserModel("Kelsea", "Jondall")); users.Add(new UserModel("Brian", "Cantrell")); users.Add(new UserModel("Tony", "Stewart")); //save the users in the cache with 60s expiration policy var policy = new CacheItemPolicy().AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60.0); cache.Set("Users", users, policy); } else { MyLogger.GetInstance().Info("Got Users from the cache"); } //return JSON serialized list of users return(new JavaScriptSerializer().Serialize(users)); }
public Vehicle AddVehicle(Vehicle vehicle) { try { if (vehicle != null) { if (vehicle.Id == 0) { _dbContext.vehicles.Add(vehicle); _dbContext.SaveChanges(); MyLogger.GetInstance().Info(vehicle.LicensePlate + " added successfully"); return(vehicle); } else { _dbContext.Entry(vehicle).State = EntityState.Modified; _dbContext.SaveChanges(); MyLogger.GetInstance().Info(vehicle.LicensePlate + " updated successfully"); return(vehicle); } } else { return(null); } } catch (Exception ex) { MyLogger.GetInstance().Info(ex.Message); return(null); } }
public ActionResult Login(UserModel user) { MyLogger.GetInstance().Info("Entering LoginController.Login()"); MyLogger.GetInstance().Info("Parameters are: new JavaScriptSerializer().Serialize(user)"); try { if (!ModelState.IsValid) { return(View("Login")); } //return "Here " + model.Username + " and " + model.Password; SecurityService ss = new SecurityService(); Boolean success = ss.Authenticate(user); if (success) { MyLogger.GetInstance().Info("Exiting LoginController.Login() with login passing"); return(View("LoginSuccess", user)); } else { MyLogger.GetInstance().Info("Exiting LoginController.Login() with login failing"); return(View("LoginFail")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception LoginController.Login()", e.Message); return(View("LoginError")); } }
public string GetUsers() { //Get the default memory cache var cache = MemoryCache.Default; //Get Users from the Cache and if Users do not exist in the Cache then put them in Cache List <UserModel> users = cache.Get("Users") as List <UserModel>; if (users == null) { //Log Message MyLogger.GetInstance().Info("Jack's App: Creating Users and putting them into the Cache."); //Create a List of Users users = new List <UserModel>(); users.Add(new UserModel("Mark", "Test1")); users.Add(new UserModel("Justine", "Test1")); users.Add(new UserModel("Brianna", "Test1")); //Save the Users in the Cache with a 60s expiration policy var policy = new CacheItemPolicy().AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60.0); cache.Set("Users", users, policy); } else { //Log Message MyLogger.GetInstance().Info("Jack's App: Got Users from the Cache."); } //Return JSON Serialized list of users return(new JavaScriptSerializer().Serialize(users)); }
// GET: Account //Landing page for website, shows user information public ActionResult Index() { try { if (Session["username"] != null) { HttpResponseMessage responseGet = GlobalVariables.WebApiClient.GetAsync("User").Result; var userList = responseGet.Content.ReadAsAsync <IEnumerable <User> >().Result; if (userList != null) { User user = userList.Where(u => u.Username == (string)Session["username"]).FirstOrDefault(); return(View(user)); } return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { MyLogger.GetInstance().Error("Exception at Home page : " + ex.Message); return(RedirectToAction("Index", "Home")); } }
public ActionResult Add(FormCollection form) //, GateVersion gateversion, Project project { MyLogger.GetInstance().Info("Creating New Project"); string objString = form["txtObject"]; msg = ""; WrapperUpdateProject model = JsonConvert.DeserializeObject <WrapperUpdateProject>(objString); if (ModelState.IsValid) { SQLManager pm = new SQLManager(); bool result = pm.AddNewProject(model); if (result == false) { msg = "Error - saving project"; MyLogger.GetInstance().Error(msg); return(RedirectToAction("ErrorView", "Project", new { message = msg })); } } return(RedirectToAction("Show", "Project")); }
public ActionResult Register(User user) { try { HttpResponseMessage responseGet = GlobalVariables.WebApiClient.GetAsync("User").Result; var userList = responseGet.Content.ReadAsAsync <IEnumerable <User> >().Result; if (userList != null) { if (userList.Where(u => u.Username == user.Username || u.Email == user.Email).Any()) { ModelState.AddModelError("Username", "User already exists."); return(View()); } else { HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("User", user).Result; MyLogger.GetInstance().Info("User Registered with username : "******"username"] = user.Username; } catch (Exception ex) { MyLogger.GetInstance().Error("Exception at user Registration : " + ex.Message); } return(RedirectToAction("Index")); }
public ActionResult GateDetail(int projectId, int gateId, int gateLine) { // string msg = ""; MyLogger.GetInstance().Info("Getting Gate Details"); SQLManager pm = new SQLManager(); WrapperViewEditProject wp = pm.GetViewForUpdateGate(projectId, gateId, gateLine); if (wp == null) { msg = "Error getting gate information"; MyLogger.GetInstance().Error(msg); return(RedirectToAction("ErrorView", "Project", new { message = msg })); } else { MyLogger.GetInstance().Info("gate info sucessfully retrieved"); } return(View(wp)); }
public int SetIDentifier(int intIdentifier, string strNumeralSystem) { try { MyLogger.GetInstance().Info("Entering the ConvertToArray Method"); switch (strNumeralSystem) { case "Western": intIdentifier = intIdentifier + 3; break; case "Indian": intIdentifier = intIdentifier + 2; break; } return(intIdentifier); } catch (Exception Ex) { MyLogger.GetInstance().Error("Error at " + MethodBase.GetCurrentMethod() + " with the error message " + Ex.Message); return(intIdentifier); } finally { MyLogger.GetInstance().Info("Exiting the ConvertToArray Method"); } }