protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; int value = 0; int.TryParse(row.Cells[2].Text, out value); // id dar userbasket Online_ShoppingEntities db = new Online_ShoppingEntities(); var bas = db.UserBaskets.FirstOrDefault(p => p.Id == value); if (bas != null) { var product = db.Products.FirstOrDefault(p => p.ProductId == bas.ProductId); if (product != null) { product.Amount += bas.Count; } db.UserBaskets.Remove(bas); db.SaveChanges(); // generate query to save database } string username = HttpContext.Current.User.Identity.Name; // refresh gridview baray gereftan data jadid var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) { GridView1.DataSource = user.UserBaskets.Where(p => p.UserId == user.UserId).Select(p => new { p.Id, p.Product.ProductName, p.Count }); GridView1.DataBind(); l_sum.Text = user.UserBaskets.Where(p => p.UserId == user.UserId) .Sum(p => p.Count * p.Product.ProductSell) .ToString() + Resources.Resource.PriceUnit; } }
public int GetItemCnt() { string username = HttpContext.Current.User.Identity.Name; Online_ShoppingEntities db = new Online_ShoppingEntities(); var user = db.Users.FirstOrDefault(p => p.UserName == username);//agar nayaft null bar migardoone if (user != null) { return(user.UserBaskets.Select(p => p.Count).Sum()); } return(0); }
protected void Login_Click(object sender, EventArgs e) { Online_ShoppingEntities db = new Online_ShoppingEntities(); if (db.Users.Any(p => p.UserName == UserName.Text && p.Password == Password.Text)) { Result.Text = "با موفقیت وارد شدید"; FormsAuthentication.SetAuthCookie(UserName.Text, true); Response.Redirect("~/Default.aspx"); } else { Result.Text = "نام کاربری یا رمز عبور اشتباه می باشد"; } }
public IQueryable <Models.Product> GetProducts(int?categoryId) { var _db = new Online_ShoppingEntities(); IQueryable <Models.Product> query = _db.Products; if (Request.QueryString.AllKeys.Any(p => p == "query")) { string querystr = Request.QueryString["query"]; query = query.Where(p => p.ProductName.Contains(querystr)); } if (categoryId.HasValue && categoryId > 0) { query = query.Where(p => p.ProductCats.Any(pc => pc.CatagoryId == categoryId)); } return(query); }
protected void Page_Load() { Online_ShoppingEntities db = new Online_ShoppingEntities(); string username = HttpContext.Current.User.Identity.Name; var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) { tb_email.Text = user.Email; tb_mobile.Text = user.Mobile; } else { Response.Redirect("~/Default.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { string username = HttpContext.Current.User.Identity.Name; Online_ShoppingEntities db = new Online_ShoppingEntities(); var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) { GridView1.DataSource = user.UserBaskets.Where(p => p.UserId == user.UserId).Select(p => new { p.Id, p.Product.ProductName, p.Count }); GridView1.DataBind(); l_sum.Text = user.UserBaskets.Where(p => p.UserId == user.UserId) .Sum(p => p.Count * p.Product.ProductSell) .ToString() + Resources.Resource.PriceUnit; } }
protected void Page_Load(object sender, EventArgs e) { string username = HttpContext.Current.User.Identity.Name; Online_ShoppingEntities db = new Online_ShoppingEntities(); var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) // Not Login { if (user.UserType != 1) // Not admin { Response.Redirect("~/Default.aspx"); } } else { Response.Redirect("~/Default.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { int id = 0; if (Request.QueryString.AllKeys.Any(p => p == "id")) { string idstr = Request.QueryString["id"]; int.TryParse(idstr, out id); Online_ShoppingEntities db = new Online_ShoppingEntities(); string username = HttpContext.Current.User.Identity.Name; // نام کاربری لاگین کرده var user = db.Users.FirstOrDefault(p => p.UserName == username); add.Enabled = user != null; var pro = db.Products.FirstOrDefault(p => p.ProductId == id); if (pro != null) { this.Page.Title = pro.ProductName; Id.Text = pro.ProductId.ToString(); Name.Text = pro.ProductName; // Sell.Text = pro.ProductSell + Resources.Resource.PriceUnit; // amount.Text = pro.Amount + Resources.Resource.ItemsCnt; ImageProduct.ImageUrl = MyConfigs.ProductImageDir + pro.ImageSrc; if (CultureInfo.CurrentCulture.Name == "fa") { info.Text = pro.ProductInfo_Fa; } else { info.Text = pro.ProductInfo_En; } if (pro.Amount < 1) { add.Enabled = false; Tb_cnt.Enabled = false; // Tb_cnt.Text = Resources.Resource.ErrorNoItems; } } } else { add.Enabled = false; Tb_cnt.Enabled = false; } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (ddlLanguages.Items.FindByValue(CultureInfo.CurrentCulture.Name) != null) { ddlLanguages.Items.FindByValue(CultureInfo.CurrentCulture.Name).Selected = true; } } hl_addproduct.Visible = false; Online_ShoppingEntities db = new Online_ShoppingEntities(); string username = HttpContext.Current.User.Identity.Name; // نام کاربری لاگین کرده var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) { hl_addproduct.Visible = user.UserType == 1; } }
protected void btn_Save_Click(object sender, EventArgs e) { Online_ShoppingEntities db = new Online_ShoppingEntities(); string username = HttpContext.Current.User.Identity.Name; var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) { user.Email = tb_email.Text; user.Mobile = tb_mobile.Text; db.SaveChanges(); LResult.Text = "اطلاعات شما با موفقیت ویرایش شد"; LResult.ForeColor = Color.Green; } else { LResult.Text = "کاربری یافت نشد"; LResult.ForeColor = Color.Red; } }
protected void add_Click(object sender, EventArgs e) { int id = 0; int.TryParse(Id.Text, out id); int cnt = 0; int.TryParse(Tb_cnt.Text, out cnt); Online_ShoppingEntities db = new Online_ShoppingEntities(); var pro = db.Products.FirstOrDefault(p => p.ProductId == id); string username = HttpContext.Current.User.Identity.Name; var user = db.Users.FirstOrDefault(p => p.UserName == username); if (pro != null && user != null) { if (cnt <= pro.Amount && cnt > 0) { pro.Amount = pro.Amount - cnt; db.UserBaskets.Add(new UserBasket() { UserId = user.UserId, BDate = DateTime.Now, Count = cnt, ProductId = id }); db.SaveChanges(); LResult.Text = Resources.Resource.ProductSuccessAdd2Basket; LResult.ForeColor = Color.Green; } else { LResult.Text = Resources.Resource.ErrorNoItems; LResult.ForeColor = Color.Red; } } else { LResult.Text = Resources.Resource.ErrorItemNotFound; LResult.ForeColor = Color.Red; } }
protected void RegisterUser_Click(object sender, EventArgs e) { Online_ShoppingEntities db = new Online_ShoppingEntities(); if (string.IsNullOrEmpty(UserName.Text) || string.IsNullOrEmpty(Password.Text) || string.IsNullOrEmpty(ConfirmPassword.Text) || string.IsNullOrEmpty(Mobile.Text) || string.IsNullOrEmpty(Email.Text) ) { LResult.Text = Resources.Resource.ErrorCompleteForm; //"لطفا فرم را به طور کامل تکمیل نمایید"; LResult.ForeColor = Color.Red; } else if (Password.Text.Length < 5) { LResult.Text = Resources.Resource.ErrorShortPass; //"طول پسورد حداقل باید 5 کاراکتر باشد"; LResult.ForeColor = Color.Red; } else if (Password.Text != ConfirmPassword.Text) { LResult.Text = Resources.Resource.ErrorValidEmailField; //"رمز عبور با تکرار آن یکسان نیست"; LResult.ForeColor = Color.Red; } else if (!Email.Text.Contains("@") || !Email.Text.Contains(".")) { LResult.Text = Resources.Resource.ErrorValidEmail; //"لطفا رایانامه معتبر وارد نمایید"; LResult.ForeColor = Color.Red; } else if (!Mobile.Text.StartsWith("09") || Mobile.Text.Length != 11) { LResult.Text = Resources.Resource.ErrorValidMobile; // "لطفا شماره همراه معتبر وارد نمایید"; LResult.ForeColor = Color.Red; } else if (db.Users.Any(p => p.UserName == UserName.Text)) { LResult.Text = Resources.Resource.ErrorRepeatUsername; //"این نام کاربری قبلا در سیستم ثبت شده است"; LResult.ForeColor = Color.Red; } else if (db.Users.Any(p => p.Email == Email.Text)) { LResult.Text = Resources.Resource.ErrorRepeatEmail; //"این رایانامه قبلا در سیستم ثبت شده است"; LResult.ForeColor = Color.Red; } else if (db.Users.Any(p => p.Mobile == Mobile.Text)) { LResult.Text = Resources.Resource.ErrorRepeatMobile; //"این موبایل قبلا در سیستم ثبت شده است"; LResult.ForeColor = Color.Red; } else if (!MyConfigs.EnableSignUp) { LResult.Text = Resources.Resource.CantRegisterRightNow; //"در حال حاضر امکان ثبت نام وجود ندارد لطفا مراجعه نمایید"; LResult.ForeColor = Color.Red; } else { db.Users.Add(new User() { Email = Email.Text, Mobile = Mobile.Text, Password = Password.Text, UserName = UserName.Text }); db.SaveChanges(); LResult.Text = Resources.Resource.UrUsernameAddSuccessfully; //"نام کاربری شما با موفقیت اضافه شد . هم اکنون می توانید به سیستم وارد شوید"; // Resources.Resource.UrUsernameAddSuccessfully LResult.ForeColor = Color.Green; } }
protected void add_Click(object sender, EventArgs e) { string username = HttpContext.Current.User.Identity.Name; Online_ShoppingEntities db = new Online_ShoppingEntities(); var user = db.Users.FirstOrDefault(p => p.UserName == username); if (user != null) // Not Login { if (user.UserType != 1) // Not admin { Response.Redirect("~/Default.aspx"); } else { int amount = 0; int sell = 0; if (!Int32.TryParse(Tb_Amount.Text, out amount)) { LResult.Text = Resources.Resource.ErrorAmountNumber; LResult.ForeColor = Color.Red; } else if (!Int32.TryParse(Tb_Sell.Text, out sell)) { LResult.Text = Resources.Resource.ErrorPriceNumber; LResult.ForeColor = Color.Red; } else if (!Fu_image.HasFile) { LResult.Text = Resources.Resource.ErrorPrivewImage; LResult.ForeColor = Color.Red; } else if (!Fu_image.FileName.EndsWith(".jpg")) { LResult.Text = Resources.Resource.ErrorPrivewImageFormat; LResult.ForeColor = Color.Red; } else { string fileName = Path.GetFileName(Fu_image.PostedFile.FileName); Fu_image.PostedFile.SaveAs(Server.MapPath(MyConfigs.ProductImageDir) + fileName); // تبدیل آدرس نسبی به آدرس حقیقی و ذخیره عکس در آنجا online_shopping.Models.Product p = new online_shopping.Models.Product() { ProductName = Tb_Name.Text, Amount = amount, ProductSell = sell, ImageSrc = fileName, ProductInfo_En = tb_InfoEa.Text, ProductInfo_Fa = tb_InfoFa.Text }; db.Products.Add(p); db.SaveChanges(); LResult.Text = Resources.Resource.AddProuct2DbSuccess; LResult.ForeColor = Color.Green; } } } else { Response.Redirect("~/Default.aspx"); } }
public GenericRepository(Online_ShoppingEntities DBEntity) { _DBEntity = DBEntity; _dbSet = _DBEntity.Set <Tbl_Entity>(); }