protected void btnPurchase_Click(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; string comic = Request.QueryString["cId"]; int comicId = Int32.Parse(comic); readers r = db.readers.SingleOrDefault(a => a.R_email == email); if (r != null) { if (!db.Purchaseds.Any(a => a.C_Id == comicId && a.R_Id == r.R_Id)) { Session["type"] = "Comic"; Session["purchase_cId"] = Request.QueryString["cId"]; Response.Redirect("~/Reader/Payment/ChoiceCoP.aspx"); } else { Response.Redirect("~/DisplayComic.aspx?cId=" + comic); } } else { Session["url"] = "~/DisplayComic.aspx?cId=" + comic; Response.Redirect("~/Authentication/login.aspx"); //Jump to login page } }
private string Vip(int paymentId, decimal amount, string method, int readerId) { try { payment n = new payment { P_Id = paymentId, P_Amount = amount, P_Currency = "MYR", P_Method = method, P_Transaction_Date = DateTime.Now, P_Type = "Vip", R_Id = readerId }; db.payments.InsertOnSubmit(n); db.SubmitChanges(); readers r = db.readers.SingleOrDefault(a => a.R_Id == readerId); if (r != null) { r.R_isvip = true; db.SubmitChanges(); } return("Success"); } catch (Exception ex) { return("Failed"); } }
protected void btnFavourite_Click(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; string comic = Request.QueryString["cId"]; int comicId = Int32.Parse(comic); readers r = db.readers.SingleOrDefault(a => a.R_email == email); if (r != null) { if (!db.Favourites.Any(a => a.C_Id == comicId && a.R_Id == r.R_Id)) { Favourite l = new Favourite { R_Id = r.R_Id, C_Id = comicId }; db.Favourites.InsertOnSubmit(l); db.SubmitChanges(); // When the Error is the favourite got this item } Response.Redirect("~/DisplayComic.aspx?cId=" + comic); } else { Session["url"] = "~/DisplayComic.aspx?cId=" + comic; Response.Redirect("~/Authentication/login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; user u = db.users.SingleOrDefault(a => a.Email == email); if (u != null) { if (u.Role == "Customer") { readers r = db.readers.SingleOrDefault(a => a.R_email == u.Email); imgProfile.Visible = true; imgProfile.ImageUrl = "~/pic/profile/" + r.R_Id + ".jpg"; } else if (u.Role == "admin") { admin r = db.admins.SingleOrDefault(a => a.A_email == u.Email); imgProfile.Visible = true; imgProfile.ImageUrl = "~/pic/profile/" + r.A_Id + ".jpg"; } else if (u.Role == "comic") { ComicCreator r = db.ComicCreators.SingleOrDefault(a => a.CC_email == u.Email); imgProfile.Visible = true; imgProfile.ImageUrl = "~/pic/profile/" + r.CC_Id + ".jpg"; } else { imgProfile.Visible = false; } } else { imgProfile.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; readers r = db.readers.SingleOrDefault(a => a.R_email == email); if (r != null) { ldsPayment.Where = "R_Id = " + r.R_Id; } else { //error page Response.Redirect("~/error.aspx?err=You didnt have the permission"); } }
protected void Page_Load(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; readers r = db.readers.SingleOrDefault(a => a.R_email == email); if (r != null) { if (Session["type"] == null || Session["purchase_cId"] == null || Session["price"] == null) { //Redirect the page Response.Redirect("~/error.aspx?err=The result cant be found"); } else { if (Session["type"].ToString() != "Vip" && Session["type"].ToString() != "Comic") { //redirect page Response.Redirect("~/error.aspx?err=The result cant be found"); } } } }
protected void Page_Load(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; if (!string.IsNullOrEmpty(email)) { readers r = db.readers.SingleOrDefault(a => a.R_email == email); if (r != null) { if (r.R_isvip) { btnDone.Visible = true; btnDone.Enabled = false; btnVip.Visible = false; } } else { //other role btnVip.Visible = false; btnDone.Visible = false; } } }
protected void btnUpdate_Click(object sender, EventArgs e) { if (Page.IsValid) { string email = txtEmail.Text; readers f = db.readers.SingleOrDefault(x => x.R_email == email); if (f != null) { int id = f.R_Id; var path = MapPath("~/pic/profile/"); string password = txtPassword.Text; string phone = txtPhoneNumber.Text; if (fuImage.HasFile) { File.Delete(path + id + ".jpg"); var img = new SimpleImage(fuImage.FileContent); img.SaveAs(path + id + ".jpg"); } f.R_NickName = txtname.Text; f.R_hash = Security.GetHash(password); //f.R_email = email; f.R_phone = phone; db.SubmitChanges(); } ; Response.Redirect("~/home.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) // Initial page load { string name = HttpContext.Current.User.Identity.Name; readers f = db.readers.SingleOrDefault(x => x.R_email == name); if (f != null) { string n = Convert.ToString(f.R_phone); txtPhoneNumber.Text = n; hfId.Value = f.R_Id.ToString(); txtname.Text = f.R_NickName; txtPassword.Text = f.R_hash; txtEmail.Text = f.R_email; gender = (char)f.R_gender; id = f.R_Id; } else { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } } }
protected void Button2_Click(object sender, EventArgs e) { int index = 0; if (Page.IsValid) { foreach (GridViewRow r in GridView1.Rows) { var chk = (CheckBox)r.Cells[0].FindControl("CheckBox1"); if (chk != null && chk.Checked) { int id = Convert.ToInt32(GridView1.DataKeys[index].Value.ToString()); readers c = db.readers.SingleOrDefault(a => a.R_Id == id); if (c != null) { c.R_BanStatus = false; db.SubmitChanges(); } } index++; } Response.Redirect("../Admin/ban.aspx"); } }
protected void imgBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if (Session["type"] == null || Session["purchase_cId"] == null || Session["price"] == null) { // Response.Redirect("~/home.aspx"); } string email = HttpContext.Current.User.Identity.Name; string type = Session["type"].ToString(); string comicId = Session["purchase_cId"].ToString(); string price = Session["price"].ToString(); readers r = db.readers.SingleOrDefault(a => a.R_email == email); Comic c = db.Comics.SingleOrDefault(a => a.C_Id.ToString() == comicId); decimal amount = decimal.Parse(price); string name = "", itemName = ""; if (r != null) { if (c != null && type == "Comic") { itemName = c.C_Title; } else if (c == null && type == "Vip") { itemName = "Vip"; } else { //error page Response.Redirect("~/home.aspx"); } //Pay pal process Refer for what are the variable are need to send http://www.paypalobjects.com/IntegrationCenter/ic_std-variable-ref-buy-now.html var redirectUrl = ""; //Mention URL to redirect content to paypal site redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]"; redirectUrl += "&first_name=" + name; //Product Name redirectUrl += "&item_name=" + itemName; //Product Amount redirectUrl += "&amount=" + amount; redirectUrl += "¤cy_code=MYR"; //Business contact paypal EmailID redirectUrl += "&[email protected]"; //Shipping charges if any, or available or using shopping cart system //redirectUrl += "&shipping=0"; //Handling charges if any, or available or using shopping cart system //redirectUrl += "&handling=0"; //Tax charges if any, or available or using shopping cart system //redirectUrl += "&tax=0"; //Quantiy of product, Here statically added quantity 1 redirectUrl += "&quantity=" + 1; //If transactioin has been successfully performed, redirect SuccessURL page- this page will be designed by developer redirectUrl += "&return=http://localhost:57613//reader/Payment/ProcessPayment.aspx"; //If transactioin has been failed, redirect FailedURL page- this page will be designed by developer redirectUrl += "&cancel_return=http://localhost:57613//reader/Payment/PaymentFailed.aspx"; Response.Redirect(redirectUrl); } else { //when the payment is not made by the reader Response.Redirect("~/home.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { string cid = Request.QueryString["cId"]; int readerId = 0; bool isVip = false, cantSee = false; char vStatus = '\0'; string email = HttpContext.Current.User.Identity.Name; Comic f = db.Comics.SingleOrDefault(o => o.C_Id.ToString() == cid); //f comic readers r = db.readers.SingleOrDefault(a => a.R_email == email); ComicCreator cc = db.ComicCreators.SingleOrDefault(a => a.CC_email == email); // cc comiccreator admin ad = db.admins.SingleOrDefault(a => a.A_email == email); if (r != null) { readerId = r.R_Id; } if (f != null) { hfId.Value = f.C_Id.ToString(); // Id is int lblName.Text = f.C_Title; lblD.Text = f.C_Description; vStatus = f.C_Status; isVip = f.C_IsForVip; cantSee = f.C_CantViewable; ComicCreator c = db.ComicCreators.SingleOrDefault( a => a.CC_Id == f.CC_Id); if (isVip == true) { lblVip.Visible = true; } lblAuthor.Text = c.CC_NickName; //get the discount lblPrice.Text = "RM" + f.C_Price; lblDiscount.Text = "RM" + Math.Round(f.C_Price * Convert.ToDecimal(0.9), 2); if (cantSee == true) { //cant see Response.Redirect("~/error.aspx?err=You didnt have the permission"); } if (cc != null) //Is comic creator { if (cc.CC_Id == f.CC_Id) // If the comic creator itself see it own comic { btnEdit.Visible = true; btnAddEpisode.Visible = true; btnRead.Visible = false; btnCantRead.Visible = false; btnFavourite.Visible = false; btnFavourited.Visible = false; btnPurchase.Visible = false; btnPurchased.Visible = false; lvEpisode.Visible = false; lvUpdate.Visible = true; btnStatus.Visible = true; string status = verifyStatus(f.C_Status); btnStatus.Text = status; lvCantView.Visible = false; } else //Other comic creator see ur comic { if (vStatus != 'V') { // Error page Response.Redirect("~/error.aspx?err=The result cant be found"); } //Default button btnFavourite.Visible = false; btnFavourited.Visible = false; btnPurchase.Visible = false; btnPurchased.Visible = false; btnCantRead.Visible = true; btnRead.Visible = false; lvCantView.Visible = true; lvCan.Visible = false; lvEpisode.Visible = false; lvOnlyVip.Visible = true; } } else if (r != null) // Is reader { if (r.R_isvip == true && isVip == true) // vip with comic vip { Purchased p = db.Purchaseds.SingleOrDefault(a => a.R_Id == readerId && a.C_Id == f.C_Id); if (p != null) //Is purchased { btnPurchase.Visible = false; btnPurchased.Visible = true; btnPurchased.Enabled = false; lvOnlyVip.Visible = false; lvEpisode.Visible = true; lvCantView.Visible = false; lvCan.Visible = true; } else { btnPurchase.Visible = true; btnPurchased.Visible = false; } Favourite fa = db.Favourites.SingleOrDefault(a => a.R_Id == readerId && a.C_Id == f.C_Id); if (fa != null) // Is Faourite { btnFavourite.Visible = false; btnFavourited.Visible = true; btnFavourited.Enabled = false; } else { btnFavourite.Visible = true; btnFavourited.Visible = false; } Episode ep = db.Episodes.SingleOrDefault(a => a.C_Id == f.C_Id && a.E_Id == 1); if (ep == null) //Didnt have episode { btnRead.Visible = false; btnCantRead.Visible = true; btnCantRead.Enabled = false; } else { btnRead.Visible = true; btnCantRead.Visible = false; } } else if (r.R_isvip == true && isVip == false) // if the reader is vip and comic not vip { Purchased p = db.Purchaseds.SingleOrDefault(a => a.R_Id == readerId && a.C_Id == f.C_Id); if (p != null) //Is purchased { btnPurchase.Visible = false; btnPurchased.Visible = true; btnPurchased.Enabled = false; lblPrice.CssClass += " discount"; lblDiscount.Visible = true; lvCantView.Visible = false; lvCan.Visible = true; lvEpisode.Visible = true; lvOnlyVip.Visible = false; } else { lblPrice.CssClass += " discount"; lblDiscount.Visible = true; lvEpisode.Visible = true; lvOnlyVip.Visible = false; lvCantView.Visible = true; btnPurchase.Visible = true; btnPurchased.Visible = false; } Favourite fa = db.Favourites.SingleOrDefault(a => a.R_Id == readerId && a.C_Id == f.C_Id); if (fa != null) // Is Faourite { btnFavourite.Visible = false; btnFavourited.Visible = true; btnFavourited.Enabled = false; } else { btnFavourite.Visible = true; btnFavourited.Visible = false; } Episode ep = db.Episodes.SingleOrDefault(a => a.C_Id == f.C_Id && a.E_Id == 1); if (ep == null) //Didnt have episode { btnRead.Visible = false; btnCantRead.Visible = true; btnCantRead.Enabled = false; } else { btnRead.Visible = true; btnCantRead.Visible = false; } } else if (r.R_isvip == false && isVip == true) { btnPurchase.Visible = false; btnPurchased.Visible = false; btnRead.Visible = false; btnCantRead.Visible = true; btnCantRead.Enabled = false; btnFavourite.Visible = false; btnFavourited.Visible = false; lvOnlyVip.Visible = true; lvEpisode.Visible = false; lvCantView.Visible = true; lvCan.Visible = false; } else { Purchased p = db.Purchaseds.SingleOrDefault(a => a.R_Id == readerId && a.C_Id == f.C_Id); if (p != null) //Is purchased { btnPurchase.Visible = false; btnPurchased.Visible = true; btnPurchased.Enabled = false; lvOnlyVip.Visible = false; lvEpisode.Visible = true; lvCantView.Visible = false; lvCan.Visible = true; } else { btnPurchase.Visible = true; btnPurchased.Visible = false; } Favourite fa = db.Favourites.SingleOrDefault(a => a.R_Id == readerId && a.C_Id == f.C_Id); if (fa != null) // Is Faourite { btnFavourite.Visible = false; btnFavourited.Visible = true; btnFavourited.Enabled = false; } else { btnFavourite.Visible = true; btnFavourited.Visible = false; } Episode ep = db.Episodes.SingleOrDefault(a => a.C_Id == f.C_Id && a.E_Id == 1); if (ep == null) //Didnt have episode { btnRead.Visible = false; btnCantRead.Visible = true; btnCantRead.Enabled = false; } else { btnRead.Visible = true; btnCantRead.Visible = false; } } if (vStatus != 'V') { // Error page Response.Redirect("~/error.aspx?err=The result cant be found"); } } else if (ad != null) //Admin { btnStatus.Visible = true; string status = verifyStatus(f.C_Status); btnStatus.Text = status; btnFail.Visible = true; btnVerify.Visible = true; btnUnverify.Visible = true; btnRead.Visible = false; btnCantRead.Visible = false; btnFavourite.Visible = false; btnFavourited.Visible = false; btnPurchase.Visible = false; btnPurchased.Visible = false; lvCantView.Visible = false; lvCan.Visible = true; lvEpisode.Visible = true; lvOnlyVip.Visible = false; } else { if (isVip == true) { btnPurchase.Visible = true; btnPurchased.Visible = false; btnRead.Visible = false; btnCantRead.Visible = true; btnCantRead.Enabled = false; btnFavourite.Visible = false; btnFavourited.Visible = false; lvEpisode.Visible = false; lvOnlyVip.Visible = true; } else { Episode ep = db.Episodes.SingleOrDefault(a => a.C_Id == f.C_Id && a.E_Id == 1); if (ep == null) //Havent Favourite { btnRead.Visible = false; btnCantRead.Visible = true; btnCantRead.Enabled = false; } else { btnRead.Visible = true; btnCantRead.Visible = false; } } //Default button btnFavourite.Visible = true; btnFavourited.Visible = false; btnPurchase.Visible = true; btnPurchased.Visible = false; if (vStatus != 'V') { // Error page Response.Redirect("~/error.aspx?err=The result cant be found"); } } //Verified the available to see all or not } else { Response.Redirect("~/error.aspx?err=The result cant be found"); } }
protected void Page_Load(object sender, EventArgs e) { DataClasses1DataContext db = new DataClasses1DataContext(); if (!IsPostBack) { string email = HttpContext.Current.User.Identity.Name; string cId = Request.QueryString["cId"]; string eId = Request.QueryString["eId"]; ComicCreator cc = db.ComicCreators.SingleOrDefault(a => a.CC_email == email); readers r = db.readers.SingleOrDefault(a => a.R_email == email); admin ad = db.admins.SingleOrDefault(a => a.A_email == email); if (!string.IsNullOrEmpty(email) || int.TryParse(cId, out int o) || Int32.TryParse(eId, out int p)) { int c_id = Int32.Parse(cId); int e_id = Int32.Parse(eId); Episode ep = db.Episodes.SingleOrDefault( a => a.E_Id == e_id && a.C_Id == c_id); Comic com = db.Comics.SingleOrDefault( a => a.C_Id == c_id); if (ep != null) { string path = Server.MapPath("/pic/comic/"); int success = 0; for (int i = 0; i <= ep.E_PageNumber; i++) { string pageEpisode = path + "/" + ep.C_Id + "/" + ep.E_Id + "/" + i + ".jpg"; if (File.Exists(pageEpisode)) { success++; } } if (success == ep.E_PageNumber) { hfEpisode.Value = ep.E_Id.ToString(); hfPageNum.Value = ep.E_PageNumber.ToString(); hfComicId.Value = ep.C_Id.ToString(); } if (com != null) { if (r != null) { if (r.R_isvip == true && com.C_IsForVip == true) { //got purchased if (!db.Purchaseds.Any(a => a.R_Id == r.R_Id && a.C_Id == com.C_Id)) { if (ep.E_Id > 5) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } } } else if (r.R_isvip == false && com.C_IsForVip == true) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } else if (r.R_isvip == true && com.C_IsForVip == false) { if (!db.Purchaseds.Any(a => a.R_Id == r.R_Id && a.C_Id == com.C_Id)) { if (ep.E_Id > 5) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } } } else { if (!db.Purchaseds.Any(a => a.R_Id == r.R_Id && a.C_Id == com.C_Id)) { if (ep.E_Id > 5) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } } } } else if (cc != null) { if (com.C_IsForVip == true) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } else { if (ep.E_Id > 5) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } } } else if (ad != null) { } else { if (com.C_IsForVip == true) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } else { if (ep.E_Id > 5) { Response.Redirect("~/error.aspx?err=You didnt have the permission"); } } } } } else { Response.Redirect("~/error.aspx?err=Result cant be found"); } } else { Response.Redirect("~/error.aspx?err=Result cant be found"); } } }
protected void btnRegister_Click(object sender, EventArgs e) { if (Page.IsValid) { int randomId = 0; Random random = new Random(); bool repeatId = false; String NickName = txtname.Text; string password = txtPassword.Text; string email = txtEmail.Text; string phone = txtPhoneNumber.Text; string gender = rblGender.Text; string newFormat = DateTime.ParseExact(TxtDob.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture) .ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime dat = DateTime.Parse(newFormat); do { randomId = random.Next(10000, 9999999); var p = db.readers.SingleOrDefault( b => b.R_Id == randomId); if (p == null) { repeatId = true; } } while (repeatId == false); var sourcePath = MapPath("~/pic/system/"); var destPath = MapPath("~/pic/profile/"); if (gender == "M") { string fileName = "male.jpg"; string oldFileName = sourcePath + fileName; string newFileName = destPath + randomId + ".jpg"; File.Copy(oldFileName, newFileName); } else { string fileName = "female.jpg"; string oldFileName = sourcePath + fileName; string newFileName = destPath + randomId + ".jpg"; File.Copy(oldFileName, newFileName); } readers r = new readers { R_Id = randomId, R_NickName = NickName, R_hash = Security.GetHash(password), R_email = email, R_birth_date = dat, R_phone = phone, R_gender = char.Parse(gender), R_register_date = DateTime.Now }; db.readers.InsertOnSubmit(r); db.SubmitChanges(); Response.Redirect("~/RegisterSucess.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { GoPay d = new GoPay(); decimal price = 0; string purchaseType = Session["type"].ToString(); int purchase = 0; string email = HttpContext.Current.User.Identity.Name; readers r = db.readers.SingleOrDefault( b => b.R_email == email); Comic c = null; if (Session["purchase_cId"] != null) { purchase = Int32.Parse(Session["purchase_cId"].ToString()); if (purchase != 0) { c = db.Comics.SingleOrDefault( a => a.C_Id == purchase); } } else { Response.Redirect("~/error.aspx?err=The result cant be found"); } if (r != null) { if (c != null && purchaseType == "Comic") { } else if (c == null && purchaseType == "Vip") { if (r.R_isvip == true) { Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/error.aspx?err=You already purchased VIP"); } } else { Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/error.aspx?err=The result cant be found"); } } else { //redirect to the error page Response.Redirect("~/error.aspx?err=You didnt have the permission"); } if (Session["price"] != null) { price = decimal.Parse(Session["price"].ToString()); } else { //error page Response.Redirect("~/home.aspx"); } string message = d.pay(price, purchaseType, "Paypal", purchase, r.R_Id); if (message.Equals("Success")) { Response.Redirect("~/Reader/Payment/PaymentSuccess.aspx"); } else { //Error Page Response.Redirect("~/error.aspx?err=Payment Error"); } }
protected void Page_Load(object sender, EventArgs e) { string email = HttpContext.Current.User.Identity.Name; readers r = db.readers.SingleOrDefault(a => a.R_email == email); string type = "", cId = ""; decimal price = 0; if (Session["type"] != null) { type = Session["type"].ToString(); } if (Session["purchase_cId"] != null) { cId = Session["purchase_cId"].ToString(); } if (r != null) { if (!string.IsNullOrEmpty(type)) { if (type == "Vip") { if (r.R_isvip != true) { price = Convert.ToDecimal(199.99); Session["price"] = price.ToString(); lblAmount.Text = price.ToString(); lblComicName.Text = "None"; lblName.Text = r.R_NickName; lblType.Text = type; } else { //Error page because got vip le Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/home.aspx"); } } else { if (!string.IsNullOrEmpty(cId)) { int comicId = Int32.Parse(cId); Comic c = db.Comics.SingleOrDefault(a => a.C_Id == comicId); if (c != null) { if (r.R_isvip == true) { price = c.C_Price * Convert.ToDecimal(0.9); } else { price = c.C_Price; } Session["price"] = price.ToString(); lblAmount.Text = price.ToString(); lblComicName.Text = c.C_Title; lblName.Text = r.R_NickName; lblType.Text = type; } else { //Didnt have the comic in the database Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/home.aspx"); } } else { //Didnt have the comic from session Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/home.aspx"); } } } else { //Error page becasue didnt have the type Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/home.aspx"); } } else { Session["purchase_cId"] = null; Session["price"] = null; Session["type"] = null; Response.Redirect("~/home.aspx"); //If the user is not the reader } }
protected void ButPwd_Click(object sender, EventArgs e) { if (Page.IsValid) { string email = txtEmail.Text; user m = db.users.SingleOrDefault(x => x.Email == email); readers c = db.readers.SingleOrDefault(x => x.R_email == email); ComicCreator cr = db.ComicCreators.SingleOrDefault(x => x.CC_email == email); admin ad = db.admins.SingleOrDefault(a => a.A_email == email); if (m == null) { cvNotMatched.IsValid = false; } else { if (c != null) { string pass = Security.GetPass(); MailMessage mm = new MailMessage("*****@*****.**", txtEmail.Text); mm.Subject = "Your password!"; mm.Body = string.Format("Hello :" + m.Email + "<p>This is your new password : <h3>" + pass + "</h3>"); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential nc = new NetworkCredential(); nc.UserName = "******"; nc.Password = "******"; smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Port = 587; smtp.Send(mm); Labmsg.Text = "Your password has been sent to " + txtEmail.Text; Labmsg.ForeColor = Color.Green; c.R_hash = Security.GetHash(pass); db.SubmitChanges(); } else if (cr != null) { string pass = Security.GetPass(); MailMessage mm = new MailMessage("*****@*****.**", txtEmail.Text); mm.Subject = "Your password!"; mm.Body = string.Format("Hello :" + m.Email + "<p>This is your new password : <h3>" + pass + "</h3>"); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential nc = new NetworkCredential(); nc.UserName = "******"; nc.Password = "******"; smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Port = 587; smtp.Send(mm); Labmsg.Text = "Your password has been sent to " + txtEmail.Text; Labmsg.ForeColor = Color.Green; cr.CC_hash = Security.GetHash(pass); db.SubmitChanges(); } else if (ad != null) { string pass = Security.GetPass(); MailMessage mm = new MailMessage("*****@*****.**", txtEmail.Text); mm.Subject = "Your password!"; mm.Body = string.Format("Hello :" + m.Email + "<p>This is your new password : <h3>" + pass + "</h3>"); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential nc = new NetworkCredential(); nc.UserName = "******"; nc.Password = "******"; smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Port = 587; smtp.Send(mm); Labmsg.Text = "Your password has been sent to " + txtEmail.Text; Labmsg.ForeColor = Color.Green; ad.A_hash = Security.GetHash(pass); db.SubmitChanges(); } else { Labmsg.Text = "The account is not register yet"; Labmsg.ForeColor = Color.Red; } } } }