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 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(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 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 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());
            }
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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 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());
        }