public List <OrganizationModel> getOrganizationsOfNotice(String userName) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "select * from organization where username" + "=@value"; command.Parameters.AddWithValue("@value", userName); MySqlDataReader reader = command.ExecuteReader(); List <OrganizationModel> orglist = new List <OrganizationModel>(); while (reader.Read()) { OrganizationModel org = new OrganizationModel(); org.Name = reader.GetString("name"); org.Address = reader.GetString("address"); org.Email = reader.GetString("email"); org.TPNo = reader.GetString("tpno"); org.Web = reader.GetString("web"); orglist.Add(org); } DbConnection.Close(); return(orglist); }
public void CreateOrganization(OrganizationModel model) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "INSERT INTO Organization (name,address,tpNo,email,web,logo,userName,password) values(@name,@address,@tpNo,@email,@web,@logo,@userName,@password)"; command.Parameters.AddWithValue("@name", model.Name); command.Parameters.AddWithValue("@address", model.Address); command.Parameters.AddWithValue("@tpNo", model.TPNo); command.Parameters.AddWithValue("@email", model.Email); command.Parameters.AddWithValue("@web", model.Web); command.Parameters.AddWithValue("@logo", model.Logo); command.Parameters.AddWithValue("@userName", model.userName); char[] temp = model.password.ToCharArray(); for (int i = 0; i < temp.Length; i++) { temp[i] = (char)((int)Convert.ToChar(temp[i]) + 5); // Hash Function } command.Parameters.AddWithValue("@password", temp); command.ExecuteNonQuery(); DbConnection.Close(); }
public OrganizationModel FindOneInOrganization(string columnName, string value) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "SELECT *,length(logo) as p_size FROM organization WHERE " + columnName + "=@value"; command.Parameters.AddWithValue("@value", value); MySqlDataReader reader = command.ExecuteReader(); OrganizationModel existing = null; if (reader.Read()) { existing = new OrganizationModel(); existing.userName = reader.GetString("username"); existing.password = reader.GetString("password"); existing.Name = reader.GetString("name"); int statusIndex = reader.GetOrdinal("p_size"); int size = reader.IsDBNull(statusIndex) ? 0 : (int)reader.GetUInt32(statusIndex); byte[] picture; if (size > 0) { picture = new byte[size]; reader.GetBytes(reader.GetOrdinal("logo"), 0, picture, 0, picture.Length); } else { picture = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Content/empty_profile.gif")); } existing.Logo = picture; } DbConnection.Close(); return(existing); }
// create new organization public ActionResult registerNewOrganization() { if (Request.HttpMethod.Equals("POST")) { OrganizationModel newOrganization = new OrganizationModel { // take data from HTML form Name = Request.Form["name"], Address = Request.Form["address"], TPNo = Request.Form["telephoneNo"], Email = Request.Form["email"], Web = Request.Form["web"], userName = Request.Form["username"], password = Request.Form["password"] }; HttpPostedFileBase file = Request.Files["picture"]; // upload profile picture if (file != null && file.ContentLength > 0) { System.IO.Stream fileStream = file.InputStream; byte[] data = new byte[file.ContentLength]; fileStream.Read(data, 0, data.Length); fileStream.Close(); newOrganization.Logo= data; } OrganizationModel existing = DBContext.GetInstance().FindOneInOrganization("username", newOrganization.userName); if (existing == null) // if there's already an organization { DBContext.GetInstance().CreateOrganization(newOrganization); } else { ViewData["success"] = 0; ViewData["hasError"] = 1; ViewData["errorMsg"] = "Username already exists"; } return RedirectToAction("OrganizationLogin", "Organization"); } return View(); }
public List<OrganizationModel> getOrganizationsOfNotice(String userName) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "select * from organization where username" + "=@value"; command.Parameters.AddWithValue("@value", userName); MySqlDataReader reader = command.ExecuteReader(); List<OrganizationModel> orglist = new List<OrganizationModel>(); while (reader.Read()) { OrganizationModel org = new OrganizationModel(); org.Name = reader.GetString("name"); org.Address = reader.GetString("address"); org.Email = reader.GetString("email"); org.TPNo = reader.GetString("tpno"); org.Web = reader.GetString("web"); orglist.Add(org); } DbConnection.Close(); return orglist; }
public OrganizationModel FindOneInOrganization(string columnName, string value) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "SELECT *,length(logo) as p_size FROM organization WHERE " + columnName + "=@value"; command.Parameters.AddWithValue("@value", value); MySqlDataReader reader = command.ExecuteReader(); OrganizationModel existing = null; if (reader.Read()) { existing = new OrganizationModel(); existing.userName = reader.GetString("username"); existing.password = reader.GetString("password"); existing.Name = reader.GetString("name"); int statusIndex = reader.GetOrdinal("p_size"); int size = reader.IsDBNull(statusIndex) ? 0 : (int)reader.GetUInt32(statusIndex); byte[] picture; if (size > 0) { picture = new byte[size]; reader.GetBytes(reader.GetOrdinal("logo"), 0, picture, 0, picture.Length); } else picture = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Content/empty_profile.gif")); existing.Logo = picture; } DbConnection.Close(); return existing; }