コード例 #1
0
        protected void btnUpDate_Click(object sender, EventArgs e)
        {
            using (SaleCarsEntities ctx = new SaleCarsEntities())
            {
                int count = ctx.Users.Where(u => u.f_Username == txtUsername.Text).Count();

                if (count == 0)
                {
                }
                else
                {
                    User cUs = CurrentContext.GetCurUser();
                    cUs.f_Name  = txtName.Text;
                    cUs.f_Email = txtEmail.Text;
                    cUs.f_DOB   = (DateTime.ParseExact(txtDate.Text, "dd/M/yyyy", null));

                    ctx.Entry(cUs).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    if (ClientScript.IsStartupScriptRegistered("updateinfo") == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(),
                                                           "updateinfo",
                                                           "alert('Cập nhật thành công!');",
                                                           true
                                                           );
                    }
                }
            }
        }
コード例 #2
0
 private void UpdateView(SaleCarsEntities ctx, Product pro)
 {
     //update view
     pro.Views++;
     ctx.Entry(pro).State = System.Data.Entity.EntityState.Modified;
     ctx.SaveChanges();
 }
コード例 #3
0
        private void UpdateQuantityAndSale(SaleCarsEntities ctx, Product pro, CartItems item)
        {
            //update quantity
            pro.Quantity -= item.Quantity;
            //update sale
            pro.Sales += item.Quantity;

            ctx.Entry(pro).State = System.Data.Entity.EntityState.Modified;
            ctx.SaveChanges();
        }
コード例 #4
0
        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            string oldPass = StringUtils.MD5(txtOldPass.Text);

            using (SaleCarsEntities ctx = new SaleCarsEntities())
            {
                int count = ctx.Users.Where(u => u.f_Username == txtUsername.Text && u.f_Password == oldPass).Count();

                if (count == 0)
                {
                    if (ClientScript.IsStartupScriptRegistered("swal") == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(),
                                                           "swal",
                                                           "alert('Mật khẩu không đúng!');",
                                                           true
                                                           );
                    }
                }
                else
                {
                    User cUs = CurrentContext.GetCurUser();
                    cUs.f_Password = StringUtils.MD5(txtNewPass.Text);

                    ctx.Entry(cUs).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    if (ClientScript.IsStartupScriptRegistered("updatepass") == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(),
                                                           "updatepass",
                                                           "alert('Đổi mật khẩu thành công!');",
                                                           true
                                                           );
                    }
                }
            }
        }