public string Details2(int?id) { if (id == null) { return("404"); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); Oraclehp ohp = new Oraclehp(); //DataSet data = ohp.Query($"select * from topics where id in (select followed from topicfollowing where following = {id})"); DataSet data = ohp.Query($"select * from topics t inner join topicfollowing tf on t.id = tf.followed where tf.following = '{id}' order by tf.created desc"); int count = data.Tables[0].Rows.Count; if (count == 0) { return("404"); } else { // return json data string json = JsonConvert.SerializeObject(data); return(json); } }
public string Create(int n) { string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; if (isAuthenticated == "false") { // redirect to home return("404"); } else { string description = HttpContext.Request.Form["description"]; string userid = HttpContext.Request.Form["userid"]; string postid = HttpContext.Request.Form["postid"]; description = description.Trim(); userid = userid.Trim(); postid = postid.Trim(); //Oraclehp ohp = new Oraclehp(); //int r = ohp.QueryCUD($"begin insert into users (email, password, username) values ({email},{password},{username});commit;end;"); Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin insert into comments (description, userid, postid) values ('{description}','{userid}', '{postid}');commit;end;"); string json = JsonConvert.SerializeObject(data); return(json); } }
public IActionResult Create(int n) { string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; if (isAuthenticated == "true") { // redirect to home return(Redirect("/")); } else { // if string email = HttpContext.Request.Form["email"]; string password = HttpContext.Request.Form["password"]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select id, email, password, username from users where email = '{email}'"); int count = data.Tables[0].Rows.Count; if (count == 0) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("emailnotfound", "Shown") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("loginemailfield", email) }); batch.Execute(); return(Redirect("/logins/create")); } else { if (data.Tables[0].Rows[0]["password"] as string != password) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("passwordwrong", "Shown") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("loginemailfield", email) }); batch.Execute(); return(Redirect("/logins/create")); } else { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("isAuthenticated", "true") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("id", data.Tables[0].Rows[0]["id"].ToString()) }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("email", data.Tables[0].Rows[0]["email"].ToString()) }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("username", data.Tables[0].Rows[0]["username"].ToString()) }); batch.Execute(); return(Redirect("/")); } } } }
public string DeleteConfirmed(int?id) { string userid = HttpContext.Request.Form["userid"]; string rid = HttpContext.Request.Form["rid"]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin delete from liks where lik = '{userid}' and likd = '{rid}';commit;end;"); string json = JsonConvert.SerializeObject(data); return(json); }
public string DeleteConfirmed(int?id) { string userid = HttpContext.Request.Form["userid"]; string topicid = HttpContext.Request.Form["topicid"]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin delete from topicfollowing where following = '{userid}' and followed = '{topicid}';commit;end;"); string json = JsonConvert.SerializeObject(data); return(json); }
public string DeleteVillage(string id) { if (id == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin delete from lbs_village where village_id = '{id}';commit;end;"); return("[]"); }
public string DeleteBuilding(string id) { if (id == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin delete from lbs_building where building_id = '{id}';commit;end;"); return("[]"); }
public string getBuildingVillageId(string code) { if (code == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(VILLAGE_ID) as VILLAGE_ID from lbs_village t where t.village_code = '{code}'"); string json = JsonConvert.SerializeObject(data); return(json); }
public string RegionExists2(string region) { if (region == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select count(*) as count from lbs_building where region = '{region}'"); string json = JsonConvert.SerializeObject(data); return(json); }
public IActionResult DeleteConfirmed(int?id) { if (id == null) { return(NotFound()); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; ViewData["isAuthenticated"] = session[1]; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from posts where id = '{id}'"); int count = data.Tables[0].Rows.Count; if (count == 0) { return(NotFound()); } else { if (isAuthenticated == "false") { // redirect to home return(Redirect("/")); } else { if (session[2] != data.Tables[0].Rows[0]["userid"].ToString()) { // redirect to home return(Redirect("/")); } else { // delete profile, delete current session from redis store, return page with profile deleted alert and js embedded to delete client side cookie Oraclehp ohp2 = new Oraclehp(); DataSet data2 = ohp2.Query($"begin delete from posts where id = '{id}';commit;end;"); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postdeletedalert", "Shown") }); batch.Execute(); return(Redirect($"/users/details/{session[2]}")); } } } }
public string VillageBuildings(string id) { if (id == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(BUILDING_ID) as BUILDING_ID, BUILDING_NAME, BUILDING_ADDRESS, LNG, LAT from LBS_BUILDING t where t.village_id = '{id}'"); if (data.Tables.Count == 0) { return("404"); } string json = JsonConvert.SerializeObject(data); return(json); }
public string DetailsBuilding(string id) { if (id == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from lbs_building where BUILDING_ID = '{id}'"); if (data.Tables.Count == 0) { return("404"); } string json = JsonConvert.SerializeObject(data); return(json); }
public string DetailsVillage(string id) { if (id == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from lbs_village where VILLAGE_ID = '{id}'"); if (data.Tables.Count == 0) { return("404"); } string json = JsonConvert.SerializeObject(data); return(json); }
public string CreateVillages() { string village_code = HttpContext.Request.Form["village_code"]; string village_name = HttpContext.Request.Form["village_name"]; string village_address = HttpContext.Request.Form["village_address"]; string village_region = HttpContext.Request.Form["village_region"]; string village_type = HttpContext.Request.Form["village_type"]; string village_x = HttpContext.Request.Form["village_x"]; string village_y = HttpContext.Request.Form["village_y"]; string village_lng = HttpContext.Request.Form["village_lng"]; string village_lat = HttpContext.Request.Form["village_lat"]; string source = HttpContext.Request.Form["source"]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin insert into lbs_village (village_code, village_name, village_address, village_region, village_type, village_x, village_y, village_lng, village_lat, source) values ('{village_code}','{village_name}','{village_address}','{village_region}','{village_type}','{village_x}','{village_y}','{village_lng}','{village_lat}','{source}');commit;end;"); return("[]"); }
// if user is logged in or not, get all topics and list them public IActionResult Index() { //Dictionary<string, string> session = HttpContext.Items["session"] as Dictionary<string, string>; //string isAuthenticated = session["isAuthenticated"]; string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from topics order by name"); DataRowCollection rows = data.Tables[0].Rows; ViewData["rows"] = rows; ViewData["isAuthenticated"] = isAuthenticated; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; return(View()); }
public string EditBuilding(string id) { if (id == null) { return("404"); } string building_number = HttpContext.Request.Form["building_number"]; string building_name = HttpContext.Request.Form["building_name"]; string building_address = HttpContext.Request.Form["building_address"]; string building_region = HttpContext.Request.Form["building_region"]; string building_type = HttpContext.Request.Form["building_type"]; List <string> errors = new List <string>(); if (building_number.Length == 0) { errors.Add("楼宇号码不能为空"); } if (building_name.Length == 0) { errors.Add("楼宇名称不能为空"); } if (building_address.Length == 0) { errors.Add("详细地址不能为空"); } if (building_region.Length == 0) { errors.Add("区域不能为空"); } if (building_type.Length == 0) { errors.Add("类型不能为空"); } if (errors.Count > 0) { return(JsonConvert.SerializeObject(errors)); } else { Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin update lbs_building set building_number ='{building_number}',building_name ='{building_name}',building_address='{building_address}',region ='{building_region}',type ='{building_type}' where building_id = '{id}';commit;end;"); return("[]"); } }
public string EditVillageBounds(string id) { if (id == null) { return("404"); } string village_name = HttpContext.Request.Form["village_name"]; string village_address = HttpContext.Request.Form["village_address"]; string village_region = HttpContext.Request.Form["village_region"]; string village_type = HttpContext.Request.Form["village_type"]; string village_bounds = HttpContext.Request.Form["village_bounds"]; List <string> errors = new List <string>(); if (village_name.Length == 0) { errors.Add("小区名称不能为空"); } if (village_address.Length == 0) { errors.Add("详细地址不能为空"); } if (village_region.Length == 0) { errors.Add("区域不能为空"); } if (village_type.Length == 0) { errors.Add("类型不能为空"); } if (village_bounds.Length == 0) { errors.Add("边界不能为空"); } if (errors.Count > 0) { return(JsonConvert.SerializeObject(errors)); } else { Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin update lbs_village set village_name ='{village_name}',village_address='{village_address}',village_region='{village_region}',village_type='{village_type}',village_bounds='{village_bounds}' where village_id = '{id}';commit;end;"); return("[]"); } }
// GET: Users/Details/5 public IActionResult Details(int?id) { if (id == null) { return(NotFound()); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select c.id,c.description,c.created,c.userid,c.postid,u.username from comments c inner join users u on c.userid = u.id inner join posts p on c.postid = p.id where c.id = {id}"); int count = data.Tables[0].Rows.Count; if (count == 0) { return(NotFound()); } else { ViewData["isAuthenticated"] = session[1]; ViewData["idonly"] = session[2]; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; ViewData["rid"] = id.ToString(); ViewData["description"] = data.Tables[0].Rows[0]["description"]; ViewData["created"] = data.Tables[0].Rows[0]["created"]; ViewData["rusername"] = data.Tables[0].Rows[0]["username"]; ViewData["userid"] = data.Tables[0].Rows[0]["userid"].ToString(); ViewData["postid"] = data.Tables[0].Rows[0]["postid"]; ViewData["21"] = session[21]; ViewData["29"] = session[29]; ViewData["36"] = session[36]; ViewResult vr = View(); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("profileupdatedalert", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postcreatedalert", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postdeletedalert", "Hidden") }); batch.Execute(); return(vr); } }
public string CreateBuildings() { string building_code = HttpContext.Request.Form["building_code"]; string building_number = HttpContext.Request.Form["building_number"]; string building_name = HttpContext.Request.Form["building_name"]; string building_address = HttpContext.Request.Form["building_address"]; string building_region = HttpContext.Request.Form["building_region"]; string building_type = HttpContext.Request.Form["building_type"]; string building_x = HttpContext.Request.Form["building_x"]; string building_y = HttpContext.Request.Form["building_y"]; string building_lng = HttpContext.Request.Form["building_lng"]; string building_lat = HttpContext.Request.Form["building_lat"]; string village_id = HttpContext.Request.Form["village_id"]; string source = HttpContext.Request.Form["source"]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin insert into lbs_building (code, building_number, building_name, building_address, region, type, x, y, lng, lat, village_id, source) values ('{building_code}','{building_number}','{building_name}','{building_address}','{building_region}','{building_type}','{building_x}','{building_y}','{building_lng}','{building_lat}',(select village_id from lbs_village where village_code = '{village_id}' and rownum<2),'{source}');commit;end;"); return("[]"); }
public string SearchVillageByCity(string text, string city) { //if (text == null) //{ // return "404"; //} if (text == "") { Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(VILLAGE_ID) as VILLAGE_ID, VILLAGE_NAME, VILLAGE_ADDRESS, VILLAGE_REGION, VILLAGE_TYPE, VILLAGE_LNG, VILLAGE_LAT, VILLAGE_BOUNDS, (select count(*) from lbs_building lb where lb.village_id = (lv.village_id)) as village_count from LBS_VILLAGE lv where lv.village_region like '%{city}%'"); string json = JsonConvert.SerializeObject(data); return(json); } else { Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(VILLAGE_ID) as VILLAGE_ID, VILLAGE_NAME, VILLAGE_ADDRESS, VILLAGE_REGION, VILLAGE_TYPE, VILLAGE_LNG, VILLAGE_LAT, VILLAGE_BOUNDS, (select count(*) from lbs_building lb where lb.village_id = (lv.village_id)) as village_count from LBS_VILLAGE lv where lv.village_region like '%{city}%' and lv.VILLAGE_NAME LIKE '%{text}%'"); string json = JsonConvert.SerializeObject(data); return(json); } }
public string SearchBuildingByCity(string text, string city) { //if (text == null) //{ // return "404"; //} if (text == "") { Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(BUILDING_ID) as BUILDING_ID, BUILDING_NAME, BUILDING_ADDRESS, LNG, LAT from lbs_building where region like '%{city}%'"); string json = JsonConvert.SerializeObject(data); return(json); } else { Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(BUILDING_ID) as BUILDING_ID, BUILDING_NAME, BUILDING_ADDRESS, LNG, LAT from lbs_building where region like '%{city}%' and BUILDING_NAME LIKE '%{text}%'"); string json = JsonConvert.SerializeObject(data); return(json); } }
public string IndexByRegion(string region) { if (region == null) { return("404"); } Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select RAWTOHEX(VILLAGE_ID) as VILLAGE_ID, VILLAGE_NAME, VILLAGE_ADDRESS, VILLAGE_REGION, VILLAGE_TYPE, VILLAGE_LNG, VILLAGE_LAT, VILLAGE_BOUNDS , (select count(*) from lbs_building lb where lb.village_id = (lv.village_id)) as village_count from lbs_village lv where lv.village_region = '{region}'"); //DataSet data2 = ohp.Query($"select * from lbs_building"); //DataSet data2 = ohp.Query($"select RAWTOHEX(BUILDING_ID) as BUILDING_ID, BUILDING_NAME, BUILDING_ADDRESS, LNG, LAT from lbs_building lb where lb.village_id = (select village_id from lbs_village lv where lv.village_name = '元电职工住宅A区')"); DataSet data2 = ohp.Query($"select RAWTOHEX(BUILDING_ID) as BUILDING_ID, BUILDING_NAME, BUILDING_ADDRESS, LNG, LAT from lbs_building lb where lb.region = '{region}'"); DataSet data3 = ohp.Query($"select RAWTOHEX(BUILDING_ID) as BUILDING_ID, BUILDING_NAME, BUILDING_ADDRESS, LNG, LAT from lbs_building lb where lb.village_id in (select village_id from lbs_village lv where rownum<2 and lv.village_region = '{region}' )"); string json = JsonConvert.SerializeObject(data); string json2 = JsonConvert.SerializeObject(data2); string json3 = JsonConvert.SerializeObject(data3); string jsonf = "["; jsonf += json + "," + json2 + "," + json3 + "]"; return(jsonf); }
public string Create(int n) { string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; if (isAuthenticated == "false") { // redirect to home return("404"); } else { // insert post data to topicfollowing and return something string userid = HttpContext.Request.Form["userid"]; string rid = HttpContext.Request.Form["rid"]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin insert into liks (lik, likd) values ('{userid}','{rid}');commit;end;"); string json = JsonConvert.SerializeObject(data); return(json); } }
public string Details3(int?id) { if (id == null) { return("404"); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from comments where postid = '{id}' order by created desc"); int count = data.Tables[0].Rows.Count; if (count == 0) { return("404"); } else { // return json data string json = JsonConvert.SerializeObject(data); return(json); } }
public IActionResult Create(int n) { string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; if (isAuthenticated == "false") { // redirect to home return(Redirect("/")); } else { string name = HttpContext.Request.Form["name"]; string description = HttpContext.Request.Form["description"]; // validation rules // All fields have to be filled out // Email field has to be of email format // Password has to have at least one character, one number, and at least eight characters long List <string> errors = new List <string>(); if (name.Length == 0) { errors.Add("postnamee"); } if (description.Length == 0) { errors.Add("postdescriptione"); } if (errors.Count > 0) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); //string errorconfirmed = ""; for (var i = 0; i < errors.Count; i++) { string error = errors[i]; /*switch (error) * { * case "emaile": * errorconfirmed = "emaile"; * break; * case "passworde": * errorconfirmed = "passworde"; * break; * case "usernamee": * errorconfirmed = "usernamee"; * break; * case "emailinvalid": * errorconfirmed = "emailinvalid"; * break; * default: * errorconfirmed = "passwordshort"; * break; * }*/ batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry(error, "Shown") }); //db.HashSet(HttpContext.Items["id"] as string, new HashEntry[] { new HashEntry(errors[i],"true") }); //db.HashSet(HttpContext.Items["id"] as string, new HashEntry[] { new HashEntry("email", email) }); //db.HashSet(HttpContext.Items["id"] as string, new HashEntry[] { new HashEntry("username", username) }); } batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postnamefield", name) }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postdescriptionfield", description) }); batch.Execute(); return(Redirect("/posts/create")); } else { // reset session[3,4,5,6,7,8,9], set session[10]/register alert to true, clean data, insert into database (hash password), redirect to login ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postnamee", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postdescriptione", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("posttopicide", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postnamefield", "") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postdescriptionfield", "") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("posttopicidfield", "") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postcreatedalert", "Shown") }); batch.Execute(); name = name.Trim(); description = description.Trim(); //Oraclehp ohp = new Oraclehp(); //int r = ohp.QueryCUD($"begin insert into users (email, password, username) values ({email},{password},{username});commit;end;"); Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"begin insert into posts (name, description, userid) values ('{name}','{description}', '{session[2]}');commit;end;"); return(Redirect($"/users/details/{session[2]}")); } } }
public IActionResult Edit(int?id, int?x) { if (id == null) { return(NotFound()); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; ViewData["isAuthenticated"] = session[1]; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from posts where id = {id}"); int count = data.Tables[0].Rows.Count; if (count == 0) { return(NotFound()); } else { if (isAuthenticated == "false") { // redirect to home return(Redirect("/")); } else { if (session[2] != data.Tables[0].Rows[0]["userid"].ToString()) { // redirect to home return(Redirect("/")); } else { // validate data and if data is invalid open/close redis connection to toggle // errors and update input fields with user entered values and redirect to // previous url string name = HttpContext.Request.Form["name"]; string description = HttpContext.Request.Form["description"]; // validation rules // All fields have to be filled out // Email field has to be of email format // Password has to have at least one character, one number, and at least eight characters long List <string> errors = new List <string>(); if (name.Length == 0) { errors.Add("updatedpostnamee"); } if (description.Length == 0) { errors.Add("updatedpostdescriptione"); } if (errors.Count > 0) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); for (var i = 0; i < errors.Count; i++) { string error = errors[i]; batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry(error, "Shown") }); } batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("updatedpostnamefield", name) }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("updatedpostdescriptionfield", description) }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postchanged", "true") }); batch.Execute(); return(Redirect(HttpContext.Request.Path)); } else { // save data into database, trigger updated profile alert, and redirect to profile page Oraclehp ohp2 = new Oraclehp(); DataSet data2 = ohp2.Query($"begin update posts set name = '{name}', description = '{description}' where id = '{id}';commit;end;"); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postupdatedalert", "Shown") }); batch.Execute(); return(Redirect($"/posts/details/{id}")); } } } } }
// GET: Users/Edit/5 public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); string isAuthenticated = session[1]; ViewData["isAuthenticated"] = session[1]; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from posts where id = {id}"); int count = data.Tables[0].Rows.Count; if (count == 0) { return(NotFound()); } else { if (isAuthenticated == "false") { // redirect to home return(Redirect("/")); } else { if (session[2] != data.Tables[0].Rows[0]["userid"].ToString()) { // redirect to home return(Redirect("/")); } else { ViewData["30"] = session[30]; ViewData["31"] = session[31]; ViewData["32"] = session[32]; ViewData["33"] = session[33]; ViewData["name"] = data.Tables[0].Rows[0]["name"]; ViewData["description"] = data.Tables[0].Rows[0]["description"]; if (session[34] == "true") { ViewData["name"] = session[32]; ViewData["description"] = session[33]; } ViewResult vr = View(); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("updatedpostnamee", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("updatedpostdescriptione", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("updatedpostnamefield", "") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("updatedpostdescriptionfield", "") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postchanged", "false") }); batch.Execute(); return(vr); } } } }
// GET: Users/Details/5 public IActionResult Details(int?id) { if (id == null) { return(NotFound()); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select p.id,p.name,p.description,p.imageurl,p.created,p.userid,p.topicid,u.username,t.name as topicname from posts p inner join users u on p.userid = u.id inner join topics t on p.topicid = t.id where p.id = {id}"); int count = data.Tables[0].Rows.Count; if (count == 0) { return(NotFound()); } else { ViewData["isAuthenticated"] = session[1]; ViewData["idonly"] = session[2]; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; ViewData["rid"] = id.ToString(); ViewData["name"] = data.Tables[0].Rows[0]["name"]; ViewData["imageurl"] = data.Tables[0].Rows[0]["imageurl"]; ViewData["description"] = data.Tables[0].Rows[0]["description"]; ViewData["created"] = data.Tables[0].Rows[0]["created"]; ViewData["rusername"] = data.Tables[0].Rows[0]["username"]; ViewData["topicname"] = data.Tables[0].Rows[0]["topicname"]; ViewData["userid"] = data.Tables[0].Rows[0]["userid"].ToString(); ViewData["topicid"] = data.Tables[0].Rows[0]["topicid"]; ViewData["21"] = session[21]; ViewData["35"] = session[35]; Oraclehp ohp2 = new Oraclehp(); DataSet likescount = ohp2.Query($"select count(*) as count from liks where likd = '{id}'"); DataSet commentscount = ohp2.Query($"select count(*) as count from comments where postid = '{id}'"); if (session[1] == "true") { // get followed posts Oraclehp ohp3 = new Oraclehp(); DataSet likedstatus = ohp3.Query($"select count(*) as count from liks where lik = '{session[2]}' and likd = '{id}'"); if (likedstatus.Tables[0].Rows[0]["count"].ToString() == "0") { ViewData["likedstatus"] = "Like"; } else { ViewData["likedstatus"] = "Unlike"; } } ViewData["likescount"] = likescount.Tables[0].Rows[0]["count"]; ViewData["commentscount"] = commentscount.Tables[0].Rows[0]["count"]; ViewResult vr = View(); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("profileupdatedalert", "Hidden") }); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("postupdatedalert", "Hidden") }); batch.Execute(); return(vr); } }
// GET: Topics/Details/5 // if user is logged out get topic, topic posts, posts count, following count, ajax list of followers // if user is logged in get same information, include follow/unfollow section, check if user has followed topic already // and if yes set value of followed else follow, include js script to follow/unfollow with ajax to make changes // to database and when done update UI public IActionResult Details(int?id) { if (id == null) { return(NotFound()); } string sessionstring = HttpContext.Request.Scheme; string[] session = sessionstring.Split(","); Oraclehp ohp = new Oraclehp(); DataSet data = ohp.Query($"select * from topics where id = '{id}'"); int count = data.Tables[0].Rows.Count; if (count == 0) { return(NotFound()); } else { // pass topic data into view, get posts from topic into view, and topicfollowing count and hidden modal into view // write js script so if user clicks on topicfollowing count ajax request // is sent to get users who have followed this topic and insert them into hidden modal and toggle modal // if close button is clicked modal is closed Oraclehp ohp2 = new Oraclehp(); DataSet posts = ohp2.Query($"select p.id,p.name,p.description,p.imageurl,p.created,p.userid,p.topicid,u.username,t.name as topicname from posts p inner join users u on p.userid = u.id inner join topics t on p.topicid = t.id where topicid = '{id}' order by created desc"); DataSet postscount = ohp2.Query($"select count(*) as count from posts where topicid = '{id}'"); DataSet followingcount = ohp2.Query($"select count(*) as count from topicfollowing where followed = '{id}'"); if (session[1] == "true") { // get followed posts Oraclehp ohp3 = new Oraclehp(); DataSet followedstatus = ohp3.Query($"select count(*) as count from topicfollowing where following = '{session[2]}' and followed = '{id}'"); if (followedstatus.Tables[0].Rows[0]["count"].ToString() == "0") { ViewData["followedstatus"] = "Follow"; } else { ViewData["followedstatus"] = "Unfollow"; } } ViewData["isAuthenticated"] = session[1]; ViewData["idonly"] = session[2]; ViewData["id"] = $"/users/details/{session[2]}"; ViewData["username"] = session[4]; ViewData["rid"] = id.ToString(); ViewData["name"] = data.Tables[0].Rows[0]["name"]; ViewData["imageurl"] = data.Tables[0].Rows[0]["imageurl"]; ViewData["description"] = data.Tables[0].Rows[0]["description"]; ViewData["posts"] = posts.Tables[0].Rows; ViewData["postscount"] = postscount.Tables[0].Rows[0]["count"]; ViewData["followingcount"] = followingcount.Tables[0].Rows[0]["count"]; ViewResult vr = View(); ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase db = redis.GetDatabase(); var batch = db.CreateBatch(); batch.HashSetAsync(session[0], new HashEntry[] { new HashEntry("profileupdatedalert", "Hidden") }); batch.Execute(); return(vr); } }
public string CreateBuilding() { string building_number = HttpContext.Request.Form["building_number"]; string building_name = HttpContext.Request.Form["building_name"]; string building_address = HttpContext.Request.Form["building_address"]; string building_region = HttpContext.Request.Form["building_region"]; string building_type = HttpContext.Request.Form["building_type"]; //string building_bounds = HttpContext.Request.Form["building_bounds"]; //string building_x = HttpContext.Request.Form["building_x"]; //string building_y = HttpContext.Request.Form["building_y"]; //string building_lng = HttpContext.Request.Form["building_lng"]; //string building_lat = HttpContext.Request.Form["building_lat"]; string source = HttpContext.Request.Form["source"]; List <string> errors = new List <string>(); if (building_number.Length == 0) { errors.Add("楼宇号码不能为空"); } if (building_name.Length == 0) { errors.Add("楼宇名称不能为空"); } if (building_address.Length == 0) { errors.Add("详细地址不能为空"); } if (building_region.Length == 0) { errors.Add("区域不能为空"); } if (building_type.Length == 0) { errors.Add("类型不能为空"); } //if (building_bounds.Length == 0) //{ // errors.Add("楼宇边界不能为空"); //} //if (building_x.Length == 0) //{ // errors.Add("楼宇经度不能为空"); //} //if (building_y.Length == 0) //{ // errors.Add("楼宇纬度不能为空"); //} //if (building_lng.Length == 0) //{ // errors.Add("楼宇经度不能为空"); //} //if (building_lng.Length == 0) //{ // errors.Add("楼宇纬度不能为空"); //} if (source.Length == 0) { errors.Add("楼宇来源不能为空"); } if (errors.Count > 0) { return(JsonConvert.SerializeObject(errors)); } else { Oraclehp ohp = new Oraclehp(); //DataSet data = ohp.Query($"begin insert into lbs_building (building_number, building_name, building_address, region, type, bounds, x, y, lng, lat, source) values ('{building_number}','{building_name}','{building_address}','{building_region}','{building_type}', '{building_bounds}','{building_x}','{building_y}','{building_lat}','{building_lng}','{source}');commit;end;"); DataSet data = ohp.Query($"begin insert into lbs_building (building_number, building_name, building_address, region, type, source) values ('{building_number}','{building_name}','{building_address}','{building_region}','{building_type}', '{source}');commit;end;"); return("[]"); } }