/// <summary> /// Test the connection to the database for the selected company. /// </summary> /// <param name="SessionCompany">The configuration entry for the company from which the connection string and connection timeout are retrieved.</param> /// <returns>Returns true if the connection could be established, otherwise returns false.</returns> /// <remarks>Created: Theo Crous 14/11/2011</remarks> //public static bool PingConnection(RegisteredCompany SessionCompany) public static string PingConnection(RegisteredCompany SessionCompany) { System.Data.SqlClient.SqlConnection con = null; try { con = new System.Data.SqlClient.SqlConnection(SessionCompany.ConnectionString); //con.ConnectionTimeout = Convert.ToInt32(SessionCompany.ConnectionTimeout); if (con.State != System.Data.ConnectionState.Open) { con.Open(); } System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("select top 1 Version from [CDS_SYS].[SYS_Version] order by VersionPadded desc", con); string result = command.ExecuteScalar().ToString(); //return true; return(result); } catch (Exception) { // Do not handle this exception //return false; return(""); } finally { if (con.State != System.Data.ConnectionState.Closed) { con.Close(); System.Data.SqlClient.SqlConnection.ClearPool(con); } } }
public ActionResult DeleteConfirmed(string id) { RegisteredCompany registeredCompany = db.RegisteredCompanies.Find(id); db.RegisteredCompanies.Remove(registeredCompany); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id,CompanyName")] RegisteredCompany registeredCompany) { if (ModelState.IsValid) { db.Entry(registeredCompany).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(registeredCompany)); }
public ActionResult Create([Bind(Include = "id,CompanyName")] RegisteredCompany registeredCompany) { if (ModelState.IsValid) { db.RegisteredCompanies.Add(registeredCompany); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(registeredCompany)); }
// GET: RegisteredCompanies/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RegisteredCompany registeredCompany = db.RegisteredCompanies.Find(id); if (registeredCompany == null) { return(HttpNotFound()); } return(View(registeredCompany)); }
/// <summary> /// Set the database connection and connection timeout for the application. These values are retrieved from the config file custom section. /// </summary> /// <param name="SessionCompany">The configuration entry for the company from which the connection string and connection timeout are retrieved.</param> /// <returns>Returns true if connection was succesful, otherwise returns false.</returns> /// <remarks>Created: Theo Crous 14/11/2011</remarks> public static bool SetConnection(RegisteredCompany SessionCompany) { try { ApplicationDataContext.Instance.SetConnections(SessionCompany.ConnectionString, true); //CDS.Client.BusinessLayer.ApplicationContext.Instance.SetConnections(SessionCompany.ConnectionString, true); ApplicationDataContext.Instance.SqlCommandTimeOut = Convert.ToInt32(SessionCompany.ConnectionTimeout); return(true); } catch (Exception ex) { if (CDS.Shared.Exception.BusinessLogicExceptionHandler.HandleException(ref ex)) { throw ex; } return(false); } }
public List <RegisteredCompany> GetRegisteredCompanies() { var Regcompanies = new List <RegisteredCompany>(); var query = db.tbl_Companies.ToList(); if (query != null) { foreach (var rc in query) { var comp = new RegisteredCompany { Id = rc.Id, RegNo = rc.RegNo, CompanyName = rc.CompanyName, Status = rc.Status, DateAdded = rc.DateAdded }; Regcompanies.Add(comp); } } return(Regcompanies); }