public ActionResult Create([Bind(Include = "ID,Name,Gender,UserID")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemple #2
0
 // POST: api/User
 public void Post(UserModel userModel)
 {
     try
     {
         modelUser.Users.Add(new UserEntity {
             Id = userModel.Id, Name = userModel.Name
         });
         modelUser.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("Post error in save to database", ex);
     }
 }
Exemple #3
0
        // GET: Doimatkhau
        public void xulydoimatkhau()
        {
            String    matkhaucu      = Request.Form["matkhau"];
            String    matkhaumoi     = Request.Form["matkhaumoi"];
            String    nhaplaimatkhau = Request.Form["nhaplaimatkhaumoi"];
            khachhang kh             = new khachhang();

            kh = (khachhang)Session["nguoidung"];
            if (matkhaucu == kh.matkhau)
            {
                if (matkhaumoi == nhaplaimatkhau && matkhaumoi != "")
                {
                    var listkh = ur.khachhang.ToList();
                    foreach (khachhang i in listkh)
                    {
                        if (i.matkhau == matkhaucu && i.tendangnhap == kh.tendangnhap)
                        {
                            i.matkhau  = matkhaumoi;
                            kh.matkhau = matkhaumoi;
                            ur.SaveChanges();
                        }
                    }
                    ViewBag.mess = "Đổi mật khẩu thành công";
                }
                else
                {
                    ViewBag.mess = "Mật khẩu nhập không khớp!!!";
                }
            }
            else
            {
                ViewBag.mess = "Mật khẩu cũ không đúng";
            }
        }
        public ActionResult Datmua()
        {
            List <CartItem> giohang        = Session["giohang"] as List <CartItem>;
            List <sanpham>  lisp           = db.sanpham.ToList();
            var             donhang        = db.donhang.ToList();
            var             chitietdonhang = db.chitietdonhang.ToList();
            donhang         dh             = new donhang();

            dh.email                 = Request.Form["email"];
            dh.diachi                = Request.Form["diachi"];
            dh.ghichu                = Request.Form["ghichu"];
            dh.ngaydathang           = DateTime.Now;
            dh.maphuongthucthanhtoan = int.Parse(Request.Form["phuongthuc"].ToString());
            dh.tenkhachhang          = Request.Form["hoten"];
            dh.tinhtrang             = "Đang chờ";
            dh.tongtienthanhtoan     = Convert.ToDecimal(Request.Form["tongtienthanhtoan"]);
            db.donhang.Add(dh);
            db.SaveChanges();
            for (int i = 0; i < giohang.Count; i++)
            {
                chitietdonhang ctdh = new chitietdonhang();
                ctdh.madonhang  = dh.madonhang;
                ctdh.masanpham  = giohang[i].masanpham;
                ctdh.soluongmua = giohang[i].soluong;
                ctdh.tensanpham = giohang[i].tensanpham;
                ctdh.dongia     = (decimal)giohang[i].dongia;
                ctdh.tongtien   = (decimal)giohang[i].thanhtien;
                db.chitietdonhang.Add(ctdh);
                // sửa lại số lượng sản phẩm trong csdl sau khi đặt mua
                sanpham sp = db.sanpham.Find(giohang[i].masanpham);
                sp.soluong = sp.soluong - giohang[i].soluong;
                db.SaveChanges();
            }
            for (int i = 0; i < giohang.Count; i++)
            {
                giohang.RemoveAt(i);
                i--;
            }



            return(RedirectToAction("Datmuathanhcong", "Home"));
        }
        public ActionResult Xulydangky()

        {
            string hoten          = Request.Form["hoten"];
            string diachi         = Request.Form["diachi"];
            string email          = Request.Form["email"];
            string sodienthoai    = Request.Form["sodienthoai"];
            string tendangnhap    = Request.Form["tendangnhap"];
            string matkhau        = Request.Form["matkhau"];
            string nhaplaimatkhau = Request.Form["nhaplaimatkhau"];

            if (matkhau == nhaplaimatkhau)
            {
                if (hoten == "" || diachi == "" || email == "" || sodienthoai == "" || tendangnhap == "" || matkhau == "")
                {
                    ViewBag.mess = "Không được để trống ";
                    return(RedirectToAction("Dangky"));
                }
                else
                {
                    WebApplication3.Models.khachhang moi = new WebApplication3.Models.khachhang();
                    moi.diachi      = diachi;
                    moi.hoten       = hoten;
                    moi.email       = email;
                    moi.sodienthoai = sodienthoai;
                    moi.tendangnhap = tendangnhap;
                    moi.matkhau     = matkhau;
                    moi.quyen       = 0;
                    ur.khachhang.Add(moi);
                    ur.SaveChanges();

                    ViewBag.mess = "Đăng ký thành công";
                    return(RedirectToAction("Index", "Sanphamuser"));
                }
            }

            else
            {
                ViewBag.mess = "Mật khẩu không khớp";
                return(RedirectToAction("Dangky"));
            }
        }
        public ActionResult danhgiasanpham(int?id)
        {
            khachhang k = (khachhang)Session["nguoidung"];
            danhgia   i = new danhgia();

            i.makhachhang = k.makhachhang;
            i.masanpham   = id;
            i.noidung     = Request.Form["noidung"];
            db.danhgia.Add(i);
            db.SaveChanges();



            return(RedirectToAction("Details/" + id));
        }