public static string forgetpassword(string password, string uniqueId) { var db = new BetaDB(); string validpassword = password.ValidatePassword(); if (validpassword == "true") { var uuniqueId = Guid.Parse(uniqueId); var IsValid = db.GUIDs.Where(x => x.UniqueId.Equals(uuniqueId)).FirstOrDefault(); Login lg = db.Logins.Find(IsValid.UserId); lg.Password = HelpUs.Encrypt(password); db.Entry(lg).State = System.Data.Entity.EntityState.Modified; var deleteGUID = db.GUIDs.SingleOrDefault(x => x.UniqueId.Equals(IsValid.UniqueId)); db.Entry(deleteGUID).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Password reset successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "server error"); return(JsonConvert.SerializeObject(dic)); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { var db = new BetaDB(); string guid = Page.RouteData.Values["guid"].ToString(); var uniqueId = Guid.Parse(guid); var IsValid = db.GUIDs.Where(x => x.UniqueId.Equals(uniqueId)).FirstOrDefault(); if (IsValid != null && IsValid.Purpose == "Activation") { Login lg = db.Logins.Find(IsValid.UserId); lg.IsActive = true; db.Entry(lg).State = System.Data.Entity.EntityState.Modified; var deleteGUID = db.GUIDs.SingleOrDefault(x => x.UniqueId.Equals(IsValid.UniqueId)); db.Entry(deleteGUID).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); AccountActivation.Visible = true; ltMessage.Text = "Account Activated Successfully!"; } else { AccountActivation.Visible = true; ltMessage.Text = "Broken Link !"; lblMessagedesc.Text = "Varify link has Experied or Invalid. Please click here to activate account"; } } catch { return; } } }
private void PopulateOrder(string invoice, List <PaypalItem> items, Amount amt) { BetaDB db = new BetaDB(); var login = db.Logins.Where(x => x.ID == userId).FirstOrDefault(); var profile = login.Profiles.ElementAt(0); var addr = profile.Address + ", " + profile.City + ", " + profile.State + ", Pin: " + profile.PinCode + ", " + profile.Country; Payment _p = new Payment(); _p.AddedOn = DateTime.Now; _p.InvoiceNo = invoice; _p.Status = 0; _p.ShippingAddress = addr; _p.Shipping = Convert.ToDecimal(amt.details.shipping); _p.Tax = Convert.ToDecimal(amt.details.tax); _p.Subtotal = Convert.ToDecimal(amt.details.subtotal); _p.UserId = userId; db.Payments.Add(_p); foreach (PaypalItem pi in items) { OrderDetail od = new OrderDetail(); od.InvoiceNo = invoice; od.Price = Convert.ToDecimal(pi.price); od.ProductId = pi.ProductId; od.UserId = userId; od.Size = pi.size; od.Quantity = pi.quantity; od.TotalAmount = Convert.ToDecimal((double)pi.quantity * pi.price); db.OrderDetails.Add(od); } db.SaveChanges(); }
public static bool IsActivate(int Id) { var user = db.Logins.Where(x => x.ID == Id).FirstOrDefault(); if (user.IsActive == false) { user.IsActive = true; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } else { user.IsActive = false; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(false); } }
public static GUID NewGuid(Login login, string _purpose) { BetaDB db = new BetaDB(); Guid UniqueCode = Guid.NewGuid(); GUID guid = new GUID() { UniqueId = UniqueCode, UserId = login.ID, CreatedOn = DateTime.Now, Purpose = _purpose }; db.GUIDs.Add(guid); db.SaveChanges(); return(guid); }
public static string ChangePassword(string password, string newpassword) { string email = HttpContext.Current.Session["email"].ToString(); var db = new BetaDB(); var oldpassword = HelpUs.Encrypt(password); var newPassword = HelpUs.Encrypt(newpassword); var User = db.Logins.Where(x => x.Email == email).FirstOrDefault(); if (User.Password != oldpassword) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Old Password did not match"); return(JsonConvert.SerializeObject(dic)); } else if (User.Password == newPassword) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "New Password Cannot be same as before"); return(JsonConvert.SerializeObject(dic)); } else { string validpassword = newpassword.ValidatePassword(); if (validpassword == "true") { User.Password = HelpUs.Encrypt(newpassword); //db.Entry(lg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Password Changed successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Password Must Contain Uppercase,Lowercase,Character and 8 Digits"); return(JsonConvert.SerializeObject(dic)); } } }
protected void btnCatSubmit_Click(object sender, EventArgs e) { lblError.Visible = true; if (catId == 0) { checkCat(txtCatName.Text.ToString().ToUpper().Trim()); if (count == 0) { ProductCategory cat = new ProductCategory() { ProductCatName = txtCatName.Text.ToString().ToUpper().Trim() }; beta.ProductCategories.Add(cat); beta.SaveChanges(); lblError.Text = "Category Added"; GetDrpCat(); ShowCat(); ClearData(); } else { lblError.Text = "Category Already Exist"; } } else { ProductCategory updatecat = beta.ProductCategories.First(sc => sc.ProductCatID.Equals(catId)); updatecat.ProductCatName = txtCatName.Text.ToString().ToUpper().Trim(); beta.SaveChanges(); lblError.Text = "Data Edited"; catId = 0; GetDrpCat(); ShowCat(); ClearData(); } }
private void InsertStock(int proId) { int drpSubcatvalue = Convert.ToInt32(drpSubCat.SelectedValue); var sizelistforstock = beta.ProductSizes.Where(s => s.ProductSubCatID.Equals(drpSubcatvalue)).ToList(); foreach (var i in sizelistforstock) { Stock insertstock = new Stock() { ProductID = proId, StockCount = 0, ProductSizeName = i.ProductSizeName }; beta.Stocks.Add(insertstock); beta.SaveChanges(); } }
protected void BtnRegister_Click(object sender, EventArgs e) { using (var db = new BetaDB()) { if (db.Logins.Count((a) => a.Email == TxtEmail.Text) > 0) { lblMessage.Text = "sorry"; } else { var encryptedpassword = HelpUs.Encrypt(TxtPassword.Text); Login lg = new Login { Email = TxtEmail.Text, Password = encryptedpassword }; db.Logins.Add(lg); db.SaveChanges(); } } }
public static string register(string email, string password) { try { var db = new BetaDB(); if (!string.IsNullOrEmpty(email) && !string.IsNullOrWhiteSpace(email)) { var emailexist = db.Logins.FirstOrDefault(x => x.Email == email); if (emailexist == null) { // checking email format bool valid = email.ValidateEmail(); if (valid == true) { Login l = new Login(); // for password requirement string validpassword = password.ValidatePassword(); if (validpassword == "true") { l.Email = email; l.Password = HelpUs.Encrypt(password); l.UserRole = "User"; l.CreatedOn = DateTime.Now; l.IsActive = false; l.Islocked = false; db.Logins.Add(l); db.SaveChanges(); //to send activation email and save data in GUID data string purpose = "Activation"; GUID UniqueCode = NewGuid(l, purpose); string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + UniqueCode.UniqueId); Sendemail(email, purpose, url); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "User Registered Successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Password Must Contain Uppercase,Lowercase,Character and 8 Digits"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email is Invalid"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "User Already Exists"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email and Password Required"); return(JsonConvert.SerializeObject(dic)); } } catch (Exception e) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Server Error"); return(JsonConvert.SerializeObject(dic)); } }
protected void Quantity_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; RepeaterItem item = (RepeaterItem)ddl.NamingContainer; BetaDB db = new BetaDB(); HiddenField hdnID = item.FindControl("ProHdn") as HiddenField; int Id = Convert.ToInt32(hdnID.Value); Label productSize = item.FindControl("lblProductSize") as Label; var size = productSize.Text; DropDownList dl = item.FindControl("Quantity") as DropDownList; int qty = Convert.ToInt32(dl.SelectedItem.Text); if (Session["email"] != null) { if (Convert.ToInt32(dl.SelectedItem.Text) != 0) { var email = Session["email"].ToString(); var userId = db.Logins.Where(x => x.Email == email).Select(x => x.ID).FirstOrDefault(); int cartId = db.Carts.Where(x => x.ProductID == Id && x.Size == size).Select(x => x.ID).FirstOrDefault(); int quantity = Convert.ToInt32(((DropDownList)item.FindControl("Quantity")).SelectedValue); Cart cart = new Cart() { ID = cartId, UserId = userId, ProductID = Id, Size = size, Quantity = quantity }; db.Entry(cart).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { CartItem ci = new CartItem { Id = Id, Quantity = qty, Size = size }; carthandler.RemoveFromCart(ci); } } else if (carthandler.GetCount() != 0) { if (Convert.ToInt32(dl.SelectedItem.Text) == 0) { CartItem ci = new CartItem { Id = Id, Quantity = qty, Size = size }; carthandler.RemoveFromCart(ci); } else { //carthandler.RemoveFromCart(Id,size); //carthandler.AddtoCart(Id, size, qty); //cookiehandler.ch.AddtoCart(Id, size, qty); //cookiehandler.AddCookie("Cart", cookiehandler.ch.products); foreach (CartItem ci in carthandler.cookiehandler.cartitems) { if (ci.Size == size && ci.Id == Id) { ci.Quantity = qty; } } carthandler.cookiehandler.SyncListItems(); } } CartDetails(); Response.Redirect(Request.Url.ToString()); }
// Payment Status == 0 then payment started // == 1 them successful payment (but waitng for approval ) // == 2 payment recieved and order processing // == 3 order processed protected void Page_Load(object sender, EventArgs e) { if ((string)Session["email"] == null) { Response.Redirect("/Home?Login=true"); Session.Clear(); } try { var paymentId = Request.Params["paymentId"].ToString(); var token = Request.Params["token"].ToString(); var payerid = Request.Params["PayerID"].ToString(); // Using the information from the redirect, setup the payment to execute. var paymentExecution = new PaymentExecution() { payer_id = payerid }; var payment = new PayPal.Api.Payment() { id = paymentId }; config = PayPal.Api.ConfigManager.Instance.GetProperties(); auth = new OAuthTokenCredential(config); var apiContext = new APIContext(auth.GetAccessToken()); BetaDB db = new BetaDB(); string email = Session["email"].ToString(); var login = db.Logins.Where(x => x.Email == email).FirstOrDefault(); var executedPayment = payment.Execute(apiContext, paymentExecution); if (executedPayment.failed_transactions == null) { List <Transaction> tl = executedPayment.transactions; foreach (Transaction transaction in tl) { String invoice = transaction.invoice_number; Payment pay = db.Payments.Where(x => x.InvoiceNo == invoice).SingleOrDefault(); pay.Status = 1; ItemList itemlist = transaction.item_list; foreach (Item i in transaction.item_list.items) { try { int id = Convert.ToInt16(i.sku); int q = Convert.ToInt16(i.quantity); string size = i.description; Cart cartitem = db.Carts.Where(x => x.ProductID == id && x.UserId == login.ID && x.Quantity == q && x.Size == size).SingleOrDefault(); String _size = cartitem.Size; Stock stock = db.Stocks.Where(pro => pro.ProductID == id && pro.ProductSizeName == size).SingleOrDefault(); stock.StockCount = stock.StockCount - Convert.ToInt16(i.quantity); db.Carts.Remove(cartitem); } catch (Exception er) { } } // Send Email to user Services.MethodHandler.Sendemail(Session["email"].ToString(), "OrderSuccess", transaction.invoice_number); // paymentlbl.Text = "We recieved you payment and your order is being processed"; } } db.SaveChanges(); } catch (Exception error) { } }