protected void Delete(object sender, EventArgs e) { Button btn = (Button)sender; int x = int.Parse(btn.CommandArgument); using (ArtShopEntities db = new ArtShopEntities()) { Art art = db.Arts.Find(x); if (art != null) { try { db.Arts.Remove(art); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Deleted Sucessful!!", "you have deleted sucessful !!")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Deleted Failed!!", "you have following exception : " + ex.Message + " !!")); } } else { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Deleted Failed!!", "Art not founds !!")); } } }
protected void confirmPayment(object sender, EventArgs e) { using (ArtShopEntities db = new ArtShopEntities()) { bank.amount -= (decimal)payments.total_pay; payments.payment_status = Guid.Parse("c595596d-8980-4138-bc20-a91056e1b1ce"); payments.payment_method = Guid.Parse("1c98a7a8-6449-4ca4-be81-8b21f1cc12e0"); payments.payment_meta = bank.bank_account; payments.customer_paid = payments.total_pay; payments.payment_date = DateTime.Now; db.Payments.AddOrUpdate(payments); db.PublicBanks.AddOrUpdate(bank); try { db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Payment sucessfull!!", "you have complete the payment using following account: " + bank.bank_account + "")); Functions.sendPaymentMail(payments); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Payment Failed!!", "you have following exception : " + ex.Message + " !!")); } } }
private void deleterowdata(int cart_id, int art_id) { try { using (ArtShopEntities db = new ArtShopEntities()) { CartDetail c = db.CartDetails.Find(cart_id, art_id); db.CartDetails.Remove(c); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( 2, Notifications.SUCCESS_TYPE, "Deleted Sucessful!!", "you have remove item form your cart !!")); } } catch (Exception e) { Functions.EnqueueNewNotifications(new Notifications( 2, Notifications.ERROR_TYPE, "Deleted Failed!!", "you have following exception : " + e.Message + " !!")); } }
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { var chk = (CheckBox)sender; var CommandName = chk.Attributes["CommandName"]; int id = int.Parse(CommandName); using (ArtShopEntities db = new ArtShopEntities()) { try { CartDetail cd = db.Carts.Find(cart_id).CartDetails.Where(c => c.art_id == id).FirstOrDefault(); cd.@checked = chk.Checked; db.CartDetails.AddOrUpdate(cd); db.SaveChanges(); total = 0; totalCount = 0; checkedCount = 0; if (check_cart_count(db)) { retriveDataAndAnalysis(db); } } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Deleted Failed!!", "you have following exception : " + ex.Message + " !!")); } } Repeater2.DataBind(); }
public static Cart CreateCart() { using (ArtShopEntities db = new ArtShopEntities()) { Cart newCart = new Cart(); newCart.user_id = (Guid)getLoginUser().ProviderUserKey; if (newCart.user_id == null) { return(null); } if (db.Carts.Count() == 0) { newCart.id = 1; } else { newCart.id = db.Carts.OrderByDescending(u => u.id).FirstOrDefault().id + 1; } try { db.Carts.Add(newCart); db.SaveChanges(); return(newCart); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Hello " + Functions.getLoginUser().UserName + " !!", "Hi, new user you can click \"Shopping Cart\" navigation at the top to check you cart!!")); } catch (Exception e) { return(null); } } }
private static void checkAddressExcite(string latlng_text, out bool created, out float lat, out float lng) { created = false; dynamic latlng = JsonConvert.DeserializeObject(latlng_text); lat = latlng["lat"]; lng = latlng["lng"]; using (ArtShopEntities db = new ArtShopEntities()) { Address[] addresss = db.Addresses.ToArray(); for (int i = 0; i < addresss.Length; i++) { if ((addresss[i].latitude == lat && addresss[i].longitude == lng)) { created = true; if (db.UserAddresses.Find(Functions.getLoginUser().ProviderUserKey, addresss[i].id) != null) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Address excites", "This address is been added to yours preference")); } else { try { UserAddress userAddress = new UserAddress(); userAddress.address_id = addresss[i].id; userAddress.UserId = (Guid)Functions.getLoginUser().ProviderUserKey; db.UserExtensions.Find(Functions.getLoginUser().ProviderUserKey).UserAddresses.Add(userAddress); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Adding successful", "Your new reference address is updates to your profiles")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unknows error founds 2", "Error : " + ex.Message)); } } } } } }
protected void Page_Load(object sender, EventArgs e) { param_id = Request.QueryString["id"]; param_type = Request.QueryString["type"]; display_in_map = (param_type == "show" || param_type == "edit"); procide_map.Enabled = !display_in_map; if (display_in_map) { using (ArtShopEntities db = new ArtShopEntities()) { address = db.Addresses.Find(Guid.Parse(param_id)); } procide_map.Text = "View Only"; } if (param_type == "remove") { using (ArtShopEntities db = new ArtShopEntities()) { try { Address add = db.Addresses.Find(Guid.Parse(param_id)); UserAddress userAddress = new UserAddress(); userAddress.UserId = (Guid)Functions.getLoginUser().ProviderUserKey; userAddress.address_id = add.id; userAddress = db.UserAddresses.Find(Functions.getLoginUser().ProviderUserKey, add.id); db.UserAddresses.Remove(userAddress); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Address removed !!", "The reference address is removed form your prefrence list.")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unknows error founds", "Error : " + ex.Message)); } } Response.Redirect("MyAccount.aspx?"); } }
protected void Button2_Click(object sender, EventArgs e) { using (ArtShopEntities db = new ArtShopEntities()) { try { updatesData(db); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Updates completed", "Your informations is up to date")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Updates fail", ex.Message)); } } }
protected void updates() { using (ArtShopEntities db = new ArtShopEntities()) { Art art = getData(db); try { db.Arts.AddOrUpdate(art); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Update completed", "you have done the updates !!")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Update Failed!!", "you have following exception : " + ex.Message + " !!")); } } Response.Redirect("ReadUpdateDeleteArt.aspx"); }
public void addAddress() { string address_text = this.form_address.Value; string latlng_text = this.form_latlng.Value; Console.Out.WriteLine("procide_map_Click"); if (latlng_text.Length <= 0) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "No address selected", "Please select a address to procide")); return; } bool created; float lat, lng; checkAddressExcite(latlng_text, out created, out lat, out lng); if (created) { return; } dynamic result = MapApiProvider.GetReverseGeocoding(lat, lng); JArray resultsDetails = result["results"]; if (result["status"] == "OK" ? resultsDetails.Count > 0 : false) { Address address = decodeGeoAddress(resultsDetails); using (ArtShopEntities db = new ArtShopEntities()) { Address old_address = db.Addresses.Where( q => q.street == address.street && q.city == address.city && q.state == address.state && q.poscode == address.poscode && q.country == address.country ).FirstOrDefault(); if (old_address != null ? db.UserAddresses.Find(Functions.getLoginUser().ProviderUserKey, old_address.id) != null: false) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Address excites", "This address is been added to yours preference")); } else { try { UserAddress userAddress = new UserAddress(); userAddress.UserId = (Guid)Functions.getLoginUser().ProviderUserKey; address.id = Guid.NewGuid(); if (old_address != null) { userAddress.address_id = old_address.id; } else { userAddress.Address = address; } db.UserExtensions.Find(Functions.getLoginUser().ProviderUserKey).UserAddresses.Add(userAddress); db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Adding successfu", "Your new reference address is updates to your profiles")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unknows error founds 1", "Error : " + ex.Message)); } } } } else { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Google Map API Error!", result["status"] + ": " + result["error_message"] + " !!")); } }
protected void confirmPayment(object sender, EventArgs e) { PayPal card = getData(); using (ArtShopEntities db = new ArtShopEntities()) { PayPal database = db.PayPals.Find(card.paypal_id); modal.Payment payments = db.Payments.Find(paymentId); if (database == null) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Invalid paypal account!!", "paypal account not corrects")); return; } if (database.paypal_id != card.paypal_id) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unassessable!!", "Account is not match")); return; } if (database.name != card.name) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unassessable!!", "Name is not match")); return; } if (database.password != card.password) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unassessable!!", "Passwords is not match")); return; } modal.Payment pay = db.Payments.Find(paymentId); if ((double)database.amount < pay.total_pay) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Not enought amount!!", "Your accocunt only remain " + database.amount)); return; } database.amount -= (decimal)pay.total_pay; payments.payment_status = Guid.Parse("c595596d-8980-4138-bc20-a91056e1b1ce"); payments.payment_method = Guid.Parse("9244ee14-b4b5-4f2c-833b-3b3c18d68764"); payments.payment_meta = database.paypal_id; payments.customer_paid = payments.total_pay; payments.payment_date = DateTime.Now; db.Payments.AddOrUpdate(payments); db.PayPals.AddOrUpdate(database); try { db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( 2, Notifications.SUCCESS_TYPE, "Payment sucessfull!!", "you have complete the payment with your paypal account: " + database.paypal_id + "")); Functions.sendPaymentMail(payments); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( 2, Notifications.ERROR_TYPE, "Payment Failed!!", "you have following exception : " + ex.Message + " !!")); } } }
protected void StepNextButton_Click(object sender, EventArgs e) { Guid userId = getUserId(); TextBox fname = (TextBox)FindControlRecursive(CreateUserWizard1, "firstName"); TextBox lname = (TextBox)FindControlRecursive(CreateUserWizard1, "lastName"); TextBox date = (TextBox)FindControlRecursive(CreateUserWizard1, "birthdayDate"); TextBox description = (TextBox)FindControlRecursive(CreateUserWizard1, "Description"); FileUpload profilePicture = (FileUpload)FindControlRecursive(CreateUserWizard1, "FileUploader"); FileUpload signature = (FileUpload)FindControlRecursive(CreateUserWizard1, "FileUploader2"); DropDownList dropDownMember = (DropDownList)FindControlRecursive(CreateUserWizard1, "ddlMembership"); CheckBox artistCheckBox = (CheckBox)FindControlRecursive(CreateUserWizard1, "ArtistOnly"); CheckBox custCheckBox = (CheckBox)FindControlRecursive(CreateUserWizard1, "CustomerOnly"); RadioButton radioMale = (RadioButton)FindControlRecursive(CreateUserWizard1, "radioMale"); modal.Artist newArtist = new modal.Artist(); modal.Customer newCustomer = new Customer(); modal.UserExtension newUserExtension = new UserExtension(); newArtist.UserId = getUserId(); newCustomer.UserId = getUserId(); newUserExtension.UserId = getUserId(); newUserExtension.first_name = fname.Text; newUserExtension.last_name = lname.Text; newUserExtension.picture = profilePicture.FileBytes; newUserExtension.gender = radioMale.Checked?"Male":"Female"; newArtist.signature = signature.FileBytes; newArtist.description = description.Text; newArtist.birthday_date = DateTime.ParseExact(date.Text, "yyyy-MM-dd", null); newCustomer.membership = dropDownMember.SelectedValue; newCustomer.birthday_date = DateTime.ParseExact(date.Text, "yyyy-MM-dd", null); using (ArtShopEntities db = new ArtShopEntities()) { Console.Out.WriteLine(userId); db.UserExtensions.Add(newUserExtension); if (artistCheckBox.Checked) { Roles.AddUserToRole(CreateUserWizard1.UserName, "Artist"); db.Artists.Add(newArtist); } if (custCheckBox.Checked) { Roles.AddUserToRole(CreateUserWizard1.UserName, "Customer"); db.Customers.Add(newCustomer); } try { db.SaveChanges(); UserExtension ue = db.UserExtensions.Find(userId); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Successful register!!", "Your registeration have sucessful. Dear " + ue.first_name + " " + ue.last_name + " welcome to sketch!!")); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Server SQL Error!!", "SQL: " + ex.Message)); } } }
protected void input_number_TextChanged(object sender, EventArgs e) { var chk = (TextBox)sender; var CommandName = chk.Attributes["CommandName"]; int id = int.Parse(CommandName); var number = chk.Text; int quantity = int.Parse(number); if (quantity <= 0) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Quantity out of bound!!", "you must enter the quantity that more than 0 !!")); return; } using (ArtShopEntities db = new ArtShopEntities()) { try { CartDetail cd = db.Carts.Find(cart_id).CartDetails.Where(c => c.art_id == id).FirstOrDefault(); if (cd.Art.@virtual == false) { if (quantity > cd.Art.Painting.quantity) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Out of stocks!!", "The following product is out of stocks !! seller only provide " + cd.Art.Painting.quantity + " items!!")); } else { cd.availability = quantity; db.CartDetails.AddOrUpdate(cd); db.SaveChanges(); total = 0; totalCount = 0; checkedCount = 0; if (check_cart_count(db)) { retriveDataAndAnalysis(db); } Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Updates complete!!", "")); } } else { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Non virtul type", "Virtual products cannot select quantity!!")); } } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Deleted Failed!!", "you have following exception : " + ex.Message + " !!")); } } Repeater2.DataBind(); }
protected void btnCheckout_event(object sender, EventArgs e) { bool allvirtual = true; PaymentDetail pd; Painting paint; using (ArtShopEntities db = new ArtShopEntities()) { IQueryable <vw_customer_cart2> x = db.vw_customer_cart2.Where(s => s.user_id == id); vw_customer_cart2[] y = x.ToArray(); modal.Payment newPaynment = new modal.Payment(); newPaynment.PaymentStatu = db.PaymentStatus.Find(Guid.Parse("20bd9f32-b531-4b7f-a89a-80babe9aa707")); newPaynment.UserId = (Guid)Functions.getLoginUser().ProviderUserKey; newPaynment.payment_date = DateTime.Now; newPaynment.id = Guid.NewGuid(); newPaynment.notes = ""; newPaynment.payment_method = Guid.Parse("1c98a7a8-6449-4ca4-be81-8b21f1cc12e0"); newPaynment.payment_meta = ""; for (int i = 0; i < x.Count(); i++) { if (y[i].@virtual) { if (y[i].@checked ?? false) { total += Convert.ToDouble(y[i].price); checkedCount++; pd = new PaymentDetail(); pd.add_date = DateTime.Now; pd.@virtual = y[i].@virtual; pd.quantity = y[i].availability; pd.art_id = y[i].id; pd.payment_id = newPaynment.id; db.CartDetails.Remove(db.CartDetails.Find(cart_id, y[i].id)); newPaynment.PaymentDetails.Add(pd); } } else { if (y[i].@checked ?? false) { total += (Convert.ToDouble(y[i].price) * (double)y[i].availability); checkedCount++; pd = new PaymentDetail(); pd.add_date = DateTime.Now; pd.@virtual = y[i].@virtual; pd.quantity = y[i].availability; pd.payment_id = newPaynment.id; pd.delivery_fee = Functions.caculateDeliveryFees(y[i], y[i].availability ?? 1); Art xart = db.Arts.Find(y[i].id); xart.Painting.quantity -= y[i].availability ?? 0; db.Arts.AddOrUpdate(xart); db.CartDetails.Remove(db.CartDetails.Find(cart_id, y[i].id)); newPaynment.PaymentDetails.Add(pd); } allvirtual |= false; } } newPaynment.net_pay = total; newPaynment.tax_change = total * 0.06; newPaynment.total_pay = total * 1.06; newPaynment.destinations_id = null; db.Payments.Add(newPaynment); try { db.SaveChanges(); if (allvirtual) { //checkout not need fill address Response.Redirect("~/pages/Payment/SelectMethod.aspx?id=" + newPaynment.id); } else { //checkout need fill address Response.Redirect("~/pages/Payment/CheckOut.aspx?id=" + newPaynment.id); } } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Error large!!", eve.Entry.Entity.GetType().Name + eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Error large!!", ve.PropertyName + ve.ErrorMessage)); } } } } }
public static void addToCart(string productId, HttpResponse Response, int quantity = 1) { CartDetail cd = new CartDetail(); if (HttpContext.Current.User.Identity.IsAuthenticated) { using (ArtShopEntities db = new ArtShopEntities()) { Cart cart = null; Guid user_id = (Guid)Functions.getLoginUser().ProviderUserKey; if (user_id == null) { Response.Redirect(Constant.LOGIN_URL); } IQueryable <Cart> carts = db.Carts.Where( s => s.user_id == user_id ); if (carts.Count() <= 0) { cart = Functions.CreateCart(); } else { cart = carts.FirstOrDefault(); } if (cart != null) { //string userid = Session["UserId"].ToString(); //user id for the logged in user string productid = productId; //get product id from the selected product int pidininteger = Int32.Parse(productid); Art product = db.Arts.Find(pidininteger); cd.art_id = pidininteger; //art id cd.availability = product.@virtual? 1: quantity; //1 means available cd.add_date = DateTime.Now; //added item must be recorded on real time\ cd.cart_id = cart.id; CartDetail old_details = db.CartDetails.Find(cart.id, cd.art_id); if (old_details != null) { if (old_details.Art.@virtual) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Art already existed in your cart", "This art that you are trying to add is already existed in your shopping cart")); } else { old_details.availability = old_details.availability + quantity; db.CartDetails.AddOrUpdate(old_details); try { db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Successfully update the quantity!", "You have successful updates \"" + old_details.Art.title + "\" to your shopping cart to " + old_details.availability + " !")); } catch (Exception) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Art already existed in your cart", "This art that you are trying to add is already existed in your shopping cart")); } } } else { db.CartDetails.Add(cd); try { db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Successfully added to shopping cart!", "You have successful added " + db.Arts.Find(cd.art_id).title + " to your shopping cart!")); } catch (Exception) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Art already existed in your cart", "This art that you are trying to add is already existed in your shopping cart")); } } } } } else { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Login required!", "You must login before trying to add in new item to cart !!")); Response.Redirect(Constant.LOGIN_URL); } }
protected void Button1_Click(object sender, EventArgs e) { Card card = getData(); using (ArtShopEntities db = new ArtShopEntities()) { Card database = db.Cards.Find(card.card_number); modal.Payment payments = db.Payments.Find(paymentId); if (database == null) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Invalid card number!!", "Wrong card numbers")); return; } if (database.ccv != card.ccv) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unassessable!!", "CCV is not match")); return; } if (database.name != card.name) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unassessable!!", "Name is not match")); return; } if (database.exp_date != card.exp_date) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Unassessable!!", "Exp date is not match")); return; } modal.Payment pay = db.Payments.Find(paymentId); if ((double)database.amount < pay.total_pay) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Not enought amount!!", "Your card is only remain " + database.amount)); return; } database.amount -= (decimal)pay.total_pay; payments.payment_status = Guid.Parse("c595596d-8980-4138-bc20-a91056e1b1ce"); payments.payment_method = Guid.Parse("9244ee14-b4b5-4f2c-833b-3b3c18d68764"); payments.payment_meta = database.card_number; payments.customer_paid = payments.total_pay; payments.payment_date = DateTime.Now; db.Payments.AddOrUpdate(payments); db.Cards.AddOrUpdate(database); try { db.SaveChanges(); Functions.EnqueueNewNotifications(new Notifications( Notifications.SUCCESS_TYPE, "Payment sucessfull!!", "you have used the card " + database.card_number + " complete the payment")); Functions.sendPaymentMail(payments); } catch (Exception ex) { Functions.EnqueueNewNotifications(new Notifications( Notifications.ERROR_TYPE, "Payment Failed!!", "you have following exception : " + ex.Message + " !!")); } } }