public ActionResult Edit(long ID) { context = new ShopLaptionDbContextDataContext(); var user = context.Users.SingleOrDefault(x => x.ID == ID); return(View(user)); }
public ActionResult Index() { context = new ShopLaptionDbContextDataContext(); var hd = context.Orders.Where(x => x.TinhTrang == false).ToList(); return(View(hd)); }
public ActionResult Index() { context = new ShopLaptionDbContextDataContext(); List <Product> products = context.Products.ToList(); return(View(products)); }
public ActionResult Edit(string MaHD) { context = new ShopLaptionDbContextDataContext(); var hd = context.Orders.SingleOrDefault(x => x.MaDH.Equals(MaHD)); return(View(hd)); }
public ActionResult Details(long ID) { context = new ShopLaptionDbContextDataContext(); var product = context.Products.SingleOrDefault(x => x.ID == ID); return(View(product)); }
public ActionResult Create(Category category) { context = new ShopLaptionDbContextDataContext(); if (ModelState.IsValid) { var check_name = context.Categories.Any(a => a.Name.Equals(category.Name)); if (check_name) { ModelState.AddModelError("", "Thương hiệu này đã tồn tại !"); return(View()); } else { category.CreatedBy = Session[CommonConstants.NAME_SESSION].ToString(); category.CreatedDate = DateTime.Now; category.Name.ToUpper(); context.Categories.InsertOnSubmit(category); context.SubmitChanges(); return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
public ActionResult HoaDonDaXuLy() { context = new ShopLaptionDbContextDataContext(); var hd = context.Orders.Where(x => x.TinhTrang == true).ToList(); return(View(hd)); }
public void SetRelatedProduct() { context = new ShopLaptionDbContextDataContext(); var listRelatedPro = context.Products.ToList(); ViewBag.RelatedProducts = listRelatedPro; }
public ActionResult Index() { context = new ShopLaptionDbContextDataContext(); List <User> users = context.Users.ToList(); return(View(users)); }
public ActionResult Index(LoginModel model) { using (ShopLaptionDbContextDataContext context = new ShopLaptionDbContextDataContext()) { int check = 0; if (ModelState.IsValid) { var res = context.Users.SingleOrDefault(x => x.UserName.Equals(model.UserName)); if (res == null) { check = 0; } else { if (res.Password == model.Password) { check = 1; } else { check = -1; } } switch (check) { case 0: { ModelState.AddModelError("", "Tài khoản không tồn tại !"); break; } case 1: { var user = context.Users.SingleOrDefault(x => x.UserName == model.UserName); var userSession = new UserLogin { UserName = user.UserName, Name = user.Name, UserID = user.ID, Permission = (int)user.Permission }; Session.Add(CommonConstants.USER_SESSION, userSession); Session.Add(CommonConstants.NAME_SESSION, userSession.Name); Session.Add(CommonConstants.IDUSER_SESSION, userSession.UserID); Session.Add(CommonConstants.PERMISSION_SESSION, userSession.Permission); return(RedirectToActionPermanent("Index", "Home")); } case -1: { ModelState.AddModelError("", "Mật khẩu không đúng !"); break; } } } return(View("Index")); } }
public ActionResult Index() { context = new ShopLaptionDbContextDataContext(); List <Category> categories = context.Categories.ToList(); return(View(categories)); }
public ActionResult FullProduct() { SetViewbag(); context = new ShopLaptionDbContextDataContext(); List <Product> products = context.Products.ToList(); return(View(products)); }
public ActionResult ShowByBrand(string brand) { SetViewbag(); SetRelatedProduct(); context = new ShopLaptionDbContextDataContext(); var brandThisProduct = context.Products.Where(x => x.Brand == brand).ToList(); return(View(brandThisProduct)); }
public ActionResult XacNhanDonHang(string MaHD) { context = new ShopLaptionDbContextDataContext(); var dh = context.Orders.SingleOrDefault(x => x.MaDH.Equals(MaHD)); dh.TinhTrang = true; context.SubmitChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(long ID) { try { context = new ShopLaptionDbContextDataContext(); var category = context.Categories.FirstOrDefault(x => x.ID == ID); context.Categories.DeleteOnSubmit(category); context.SubmitChanges(); return(RedirectToAction("Index")); } catch (Exception) { return(RedirectToAction("Index")); } }
public ActionResult Details(string MaHD) { context = new ShopLaptionDbContextDataContext(); List <OrderDetail> ctHD = context.OrderDetails.Where(x => x.MaDH.Equals(MaHD)).ToList(); var temp = context.OrderDetails.FirstOrDefault(x => x.MaDH.Equals(MaHD)); var dh = context.Orders.SingleOrDefault(x => x.MaDH == MaHD); ViewBag.CTDonhang = dh; ViewBag.TongTien = temp.Tong; // Tổng này là tổng của 1 món hàng hóa thôi mà. ViewBag.MaHoaDon = temp.MaDH; return(View(ctHD)); }
public ActionResult Edit(User account) { context = new ShopLaptionDbContextDataContext(); if (ModelState.IsValid) { var user = context.Users.SingleOrDefault(x => x.ID == account.ID); user.Name = account.Name; user.Address = account.Address; user.Email = account.Email; user.Phone = account.Phone; user.ModifiedDate = DateTime.Now; user.ModifiedBy = Session[CommonConstants.NAME_SESSION].ToString(); context.SubmitChanges(); return(RedirectToAction("Index")); } return(View("Index")); }
public ActionResult Create(User user) { context = new ShopLaptionDbContextDataContext(); if (ModelState.IsValid) { var check_user = context.Users.Any(a => a.UserName.Equals(user.UserName)); var check_email = context.Users.Any(a => a.Email.Equals(user.Email)); var res_val = new MyValidate(); if (check_user) { ModelState.AddModelError("", "Tài khoản đã tồn tại !"); return(View()); } else if (check_email) { ModelState.AddModelError("", "Email đã tồn tại !"); return(View()); } else if (res_val.isEmail(user.Email) == false) { ModelState.AddModelError("", "Email không đúng định dạng !"); return(View()); } else if (res_val.IsValidPhone(user.Phone) == false) { ModelState.AddModelError("", "Số điện thoại không đúng !"); return(View()); } else { user.CreatedBy = Session[CommonConstants.NAME_SESSION].ToString(); user.CreatedDate = DateTime.Now; context.Users.InsertOnSubmit(user); context.SubmitChanges(); return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
public ActionResult Delete(long ID) { try { context = new ShopLaptionDbContextDataContext(); //if (Session[CommonConstants.PERMISSION_SESSION == 1]) //{ //} var user = context.Users.FirstOrDefault(x => x.ID == ID); context.Users.DeleteOnSubmit(user); context.SubmitChanges(); return(RedirectToAction("Index")); } catch (Exception) { return(RedirectToAction("Index")); } }
public ActionResult Edit(Order order) { context = new ShopLaptionDbContextDataContext(); try { if (ModelState.IsValid) { var hd = context.Orders.SingleOrDefault(x => x.MaDH.Equals(order.MaDH)); hd.DiaChi = order.DiaChi; hd.GhiChu = order.GhiChu; context.SubmitChanges(); } return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError("", "Chỉnh sửa thất bại !"); return(View()); } }
public ActionResult Delete(string MaHD) { try { context = new ShopLaptionDbContextDataContext(); var hd = context.Orders.FirstOrDefault(x => x.MaDH == MaHD); var cthd = context.OrderDetails.FirstOrDefault(x => x.MaDH == MaHD); context.Orders.DeleteOnSubmit(hd); context.SubmitChanges(); context.OrderDetails.DeleteOnSubmit(cthd); context.SubmitChanges(); return(RedirectToAction("Index")); } catch (Exception) { return(RedirectToAction("Index")); } }
public ActionResult Create(Product product, HttpPostedFileBase image) { context = new ShopLaptionDbContextDataContext(); if (image != null && image.ContentLength > 0) { //product.ImageByte = new byte[image.ContentLength]; //image.InputStream.Read(product.ImageByte, 0, image.ContentLength); string filename = System.IO.Path.GetFileName(image.FileName); string urlname = Server.MapPath("~/Assets/Image/Product/General/" + filename); image.SaveAs(urlname); product.Image = "~/Assets/Image/Product/General/" + filename; } if (ModelState.IsValid) { var check_product_code = context.Products.Any(a => a.Code.Equals(product.Code)); if (check_product_code) { ModelState.AddModelError("", "Mã sản phẩm đã tồn tại !"); return(View()); } else { product.CreatedBy = Session[CommonConstants.NAME_SESSION].ToString(); product.CreatedDate = DateTime.Now; product.Name.ToUpper(); context.Products.InsertOnSubmit(product); context.SubmitChanges(); return(RedirectToAction("Index")); } } SetViewbag(); return(View(product)); }
public ActionResult Edit(Product product, HttpPostedFileBase image) { SetViewbag(); context = new ShopLaptionDbContextDataContext(); if (ModelState.IsValid) { var proc = context.Products.SingleOrDefault(x => x.ID == product.ID); if (image != null && image.ContentLength > 0) { string filename = System.IO.Path.GetFileName(image.FileName); string urlname = Server.MapPath("~/Assets/Image/Product/General/" + filename); image.SaveAs(urlname); proc.Image = "~/Assets/Image/Product/General/" + filename; } proc.Name = product.Name; proc.Code = product.Code; proc.Brand = product.Brand; proc.Description = product.Description; proc.Price = product.Price; proc.Quantity = product.Quantity; proc.Screen = product.Screen; proc.CPU = product.CPU; proc.RAM = product.RAM; proc.Card = product.Card; proc.Disk = product.Disk; proc.ModifiedDate = DateTime.Now; proc.ModifiedBy = Session[CommonConstants.NAME_SESSION].ToString(); context.SubmitChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public CategoryDao() { context = new ShopLaptionDbContextDataContext(); }
public ActionResult DatHang(FormCollection collection) { context = new ShopLaptionDbContextDataContext(); SetViewbag(); SetListOrder(); ViewBag.TongTien = TongTien(); var res = new MyValidate(); Order order = new Order(); List <GioHang> gioHangs = GetOrders(); order.MaDH = "HD" + DateTime.Now.ToString("yyyyMMddHHmmsss"); order.TenKH = collection["tenKH"]; order.Sdt = collection["sdt"]; order.DiaChi = collection["diachi"]; order.NgayDat = DateTime.Now; order.GhiChu = collection["ghichu"]; order.TinhTrang = false; //bool v = res.IsValidPhone(order.Sdt); if (String.IsNullOrEmpty(order.TenKH)) { ViewData["err1"] = "Vui lòng nhập họ tên của bạn !"; } else if (String.IsNullOrEmpty(order.Sdt)) { ViewData["err2"] = "Vui lòng nhập số điện thoại liên lạc !"; } else if (res.IsValidPhone(order.Sdt) == false) { ViewData["err3"] = "Số điện thoại bạn nhập không đúng định dạng!"; } else if (String.IsNullOrEmpty(order.DiaChi)) { ViewData["err4"] = "Vui lòng nhập địa chỉ giao hàng !"; } else { context.Orders.InsertOnSubmit(order); context.SubmitChanges(); foreach (var item in gioHangs) { OrderDetail orderDetail = new OrderDetail(); orderDetail.MaDH = order.MaDH; orderDetail.MaSP = item.masp; orderDetail.TenSP = item.tensp; orderDetail.Soluong = item.sl; orderDetail.DonGia = (decimal)item.gia; orderDetail.Tong = (decimal)TongTien(); var pro = context.Products.SingleOrDefault(x => x.Code == orderDetail.MaSP); pro.Quantity = pro.Quantity - orderDetail.Soluong; context.OrderDetails.InsertOnSubmit(orderDetail); context.SubmitChanges(); } context.SubmitChanges(); Session["order"] = null; return(RedirectToAction("XacNhanDonHang", "Card")); } return(View()); }