forked from Mohammed4mach/Recipehub-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unfollow.aspx.cs
51 lines (42 loc) · 1.58 KB
/
unfollow.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Recipehub
{
public partial class unfollow : System.Web.UI.Page
{
public string err;
protected void Page_Load(object sender, EventArgs e)
{
if(Request.Cookies["recipehub_user_id"] == null)
{
Response.Redirect("~/Sign in.aspx");
Response.End();
}
int flwr_id = int.Parse(Request.Cookies["recipehub_user_id"].Value);
int flw_id = int.Parse(Request.QueryString["usrid"]);
MySqlConnection conn = new MySqlConnection("server=127.0.0.1;user=root;password=root;database=recipehub;");
try
{
conn.Open();
// Deleting specified record
string sql = $"DELETE FROM follow_usr WHERE flwr_user_id = {flwr_id} AND flw_user_id = {flw_id};";
Func.executeSQL(conn, sql, false);
/* Decrementing following and followers fields */
sql = $"UPDATE user SET following = following - 1 WHERE user_id = {flwr_id}; UPDATE user SET followers = followers - 1 WHERE user_id = {flw_id};";
Func.executeSQL(conn, sql, false);
conn.Close();
}
catch(Exception ex)
{
err = ex.Message;
}
Response.Redirect("~/Profile Page.aspx?usrid=" + flw_id);
}
}
}