public void CreateBidder(BidderModel model) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "INSERT INTO bidder (name,address,tpNo,profilePic,userName,password) values(@name,@address,@tpNo,@profilePic,@userName,@password)"; command.Parameters.AddWithValue("@name", model.Name); command.Parameters.AddWithValue("@address", model.Address); command.Parameters.AddWithValue("@tpNo", model.tpNo); command.Parameters.AddWithValue("@profilePic", model.ProfilePic); 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 void CreateBidder(BidderModel model) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "INSERT INTO bidder (name,address,tpNo,profilePic,userName,password) values(@name,@address,@tpNo,@profilePic,@userName,@password)"; command.Parameters.AddWithValue("@name", model.Name); command.Parameters.AddWithValue("@address", model.Address); command.Parameters.AddWithValue("@tpNo", model.tpNo); command.Parameters.AddWithValue("@profilePic", model.ProfilePic); 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 BidderModel FindOneInBidder(string columnName, string value) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "SELECT *,length(profilePic) as p_size FROM bidder WHERE " + columnName + "=@value"; command.Parameters.AddWithValue("@value", value); MySqlDataReader reader = command.ExecuteReader(); BidderModel existing = null; if (reader.Read()) { existing = new BidderModel(); 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("profilePic"), 0, picture, 0, picture.Length); } else { picture = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Content/empty_profile.gif")); } existing.ProfilePic = picture; } DbConnection.Close(); return(existing); }
// create a new bidder instance public ActionResult registerNewBidder() { if (Request.HttpMethod.Equals("POST")) { BidderModel newBidder = new BidderModel() { Name = Request.Form["name"], // take data from HTML form Address = Request.Form["address"], tpNo = Request.Form["telephoneNo"], userName = Request.Form["username"], password = Request.Form["password"] }; HttpPostedFileBase file = Request.Files["picture"]; if (file != null && file.ContentLength > 0) // upload file { System.IO.Stream fileStream = file.InputStream; byte[] data= new byte[file.ContentLength]; fileStream.Read(data, 0, data.Length); fileStream.Close(); newBidder.ProfilePic= data; } BidderModel existing = DBContext.GetInstance().FindOneInBidder("username", newBidder.userName); if (existing == null) // see weather this this user is already existing. { DBContext.GetInstance().CreateBidder(newBidder); // create db entry if (Request.Form["chq1"] != null && Request.Form["chq1"] == "on") { FieldListModel field = new FieldListModel(); // registered fields field.FieldName = "canteens"; field.UserName = newBidder.userName; DBContext.GetInstance().CreateFieldListEntry(field); } if (Request.Form["chq2"] != null && Request.Form["chq2"] == "on") { FieldListModel field = new FieldListModel(); field.FieldName = "cleaning services"; field.UserName = newBidder.userName; DBContext.GetInstance().CreateFieldListEntry(field); } if (Request.Form["chq3"] != null && Request.Form["chq3"] == "on") { FieldListModel field = new FieldListModel(); field.FieldName = "construction"; field.UserName = newBidder.userName; DBContext.GetInstance().CreateFieldListEntry(field); } if (Request.Form["chq4"] != null && Request.Form["chq4"] == "on") { FieldListModel field = new FieldListModel(); field.FieldName = "delivery services"; field.UserName = newBidder.userName; DBContext.GetInstance().CreateFieldListEntry(field); } if (Request.Form["chq5"] != null && Request.Form["chq5"] == "on") { FieldListModel field = new FieldListModel(); field.FieldName = "security services"; field.UserName = newBidder.userName; DBContext.GetInstance().CreateFieldListEntry(field); } if (Request.Form["chq6"] != null && Request.Form["chq6"] == "on") { FieldListModel field = new FieldListModel(); field.FieldName = "vehicles"; field.UserName = newBidder.userName; DBContext.GetInstance().CreateFieldListEntry(field); } } else { ViewData["success"] = 0; ViewData["hasError"] = 1; ViewData["errorMsg"] = "Username already exists"; } return RedirectToAction("Bidderlogin", "Bidder"); } return View(); }
public BidderModel FindOneInBidder(string columnName, string value) { DbConnection.Open(); MySqlCommand command = DbConnection.CreateCommand(); command.CommandText = "SELECT *,length(profilePic) as p_size FROM bidder WHERE " + columnName + "=@value"; command.Parameters.AddWithValue("@value", value); MySqlDataReader reader = command.ExecuteReader(); BidderModel existing = null; if (reader.Read()) { existing = new BidderModel(); 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("profilePic"), 0, picture, 0, picture.Length); } else picture = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Content/empty_profile.gif")); existing.ProfilePic = picture; } DbConnection.Close(); return existing; }