Ejemplo n.º 1
0
        public static int addOder(ModelView.OderView item)
        {
            db = new ShopOnlineEntities();
            try
            {
                Oder od = new Oder
                {
                    CustAddress = item.CustAddress,

                    CustEmail = item.CustEmail,
                    CustName  = item.CustName,
                    CustPhone = item.CustPhone,
                    DayCreate = DateTime.Now,
                    IDU       = item.IDU,
                    Zipcode   = "Hihi"
                };
                db.Oders.Add(od);
                db.SaveChanges();
                return(od.id);
            }
            catch (Exception)
            {
                throw;
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static List <ModelView.ProductView> getListTitle(int pagesize)
        {
            db = new ShopOnlineEntities();
            //var rs = db.Products.OrderByDescending(p => p.id).Take(pagesize).Where(p => p.StatusProd == 1).Select(p => new ModelView.ProductView
            //{
            //    id = p.id,
            //    IDC = p.IDC ?? 0,
            //    CateName = p.Category.name,
            //    name = p.name,
            //    description = p.description,
            //    picture = (
            //          p.ProImages.Where(i => i.IDP == p.id && i.StatusIMG == 1).FirstOrDefault()
            //          ).Name,
            //    price = p.price,
            //    StatusProd = p.StatusProd,
            //    stock = p.stock
            //}).ToList();
            List <ModelView.ProductView> dt = (from a in db.Products
                                               from b in db.ProImages
                                               where a.id == b.IDP && b.StatusIMG == 1 && a.StatusProd == 1
                                               select new ModelView.ProductView
            {
                id = a.id,
                IDC = a.IDC ?? 0,
                CateName = a.Category.name,
                name = a.name,
                description = a.description,
                picture = b.Name,
                price = a.price,
                StatusProd = a.StatusProd,
                stock = a.stock
            }).OrderByDescending(a => a.id).Take(pagesize).ToList();

            return(dt);
        }
Ejemplo n.º 3
0
        public static bool addProduct(ModelView.ProductView item, HttpPostedFileBase picture)
        {
            try
            {
                db = new ShopOnlineEntities();
                Product p = new Product
                {
                    name        = item.name,
                    price       = item.price,
                    stock       = item.stock,
                    IDC         = item.IDC,
                    description = item.description,
                    StatusProd  = 1
                };
                db.Products.Add(p);
                db.SaveChanges();
                ProImage img = new ProImage
                {
                    Name      = picture.FileName,
                    IDP       = p.id,
                    StatusIMG = 1
                };
                db.ProImages.Add(img);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(false);
        }
Ejemplo n.º 4
0
        public static List <Oder> getListOder()
        {
            db = new ShopOnlineEntities();
            IQueryable <Oder> rs = from a in db.Oders select a;

            return(rs.ToList());
        }
Ejemplo n.º 5
0
        public static ModelView.UserView getUserId(int Id)
        {
            db = new ShopOnlineEntities();
            WebUser user1 = db.WebUsers.Find(Id) as WebUser;

            ModelView.UserView uv = new ModelView.UserView();
            try
            {
                uv.id       = user1.ID;
                uv.name     = user1.name;
                uv.uAddress = user1.uAddress;
                uv.email    = user1.email;
                uv.pwd      = user1.pwd;
                uv.repwd    = user1.pwd;
                uv.phone    = user1.phone;
                uv.zipcode  = user1.zipcode;
                uv.username = user1.username;
                uv.avatar   = user1.avatar;
                return(uv);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(uv);
        }
Ejemplo n.º 6
0
        public static List <Category> getListCate()
        {
            db = new ShopOnlineEntities();
            var result = from viet in db.Categories where viet.StatusCat == 1 select viet;

            return(result.ToList());
        }
Ejemplo n.º 7
0
 public static bool addUser(ModelView.UserView item)
 {
     db = new ShopOnlineEntities();
     try
     {
         WebUser user = new WebUser
         {
             username = item.username,
             email    = item.email,
             //Mã hóa
             pwd      = Encrypt(item.pwd),
             name     = item.name,
             uAddress = item.uAddress,
             phone    = item.phone,
             zipcode  = item.zipcode
         };
         db.WebUsers.Add(user);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Ejemplo n.º 8
0
        public static bool AddNewImage(ModelView.ProImageView item)
        {
            ShopOnlineEntities en = new ShopOnlineEntities();
            ProImage           pi = new ProImage {
                Name = item.Name, IDP = item.IDP, StatusIMG = item.StatusIMG
            };

            en.ProImages.Add(pi);
            return(en.SaveChanges() > 0);
        }
Ejemplo n.º 9
0
        public static bool addCate(ModelView.Category item)
        {
            db = new ShopOnlineEntities();
            Category cate = new Category {
                name      = item.name,
                StatusCat = 1
            };

            db.Categories.Add(cate);
            return(db.SaveChanges() > 0);
        }
Ejemplo n.º 10
0
        public static ModelView.Category GetCatByID(int id)
        {
            db = new ShopOnlineEntities();
            var rs = db.Categories.Where(c => c.id == id).Select(c => new ModelView.Category {
                ID           = c.id,
                name         = c.name,
                statusCat    = c.StatusCat,
                ProductCount = c.Products.Where(d => d.IDC == c.id && d.StatusProd == 1).Select(d => d.id).Count()
            }).FirstOrDefault();

            return(rs);
        }
Ejemplo n.º 11
0
        public static List <ModelView.Category> GetList()
        {
            db = new ShopOnlineEntities();
            var rs = db.Categories.Where(c => c.StatusCat == 1).Select(c => new ModelView.Category
            {
                ID           = c.id,
                name         = c.name,
                statusCat    = c.StatusCat,
                ProductCount = c.Products.Where(d => d.IDC == c.id && d.StatusProd == 1).Select(d => d.id).Count()
            }).ToList();

            return(rs);
        }
Ejemplo n.º 12
0
        public static List <ModelView.ProductView> getListPro()
        {
            db = new ShopOnlineEntities();

            /*
             * lambda
             */
            List <ModelView.ProductView> q = db.Products.Where(d => d.StatusProd == 1).Select(d => new ModelView.ProductView
            {
                id      = d.id,
                picture = d.ProImages.Where(f => f.StatusIMG == 1).FirstOrDefault().Name
            }).ToList();

            /*
             * select p.*,pi.name
             * from product p, proImage pi
             * where p.id=pi.idp and p.statusprod=1 and pi.status=1
             */

            IQueryable <ModelView.ProductView> rs = from p in db.Products
                                                    from pi in db.ProImages
                                                    where p.id == pi.IDP && p.StatusProd == 1 && pi.StatusIMG == 1
                                                    select new ModelView.ProductView {
                id = p.id, picture = pi.Name
            };

            /*
             * select p.*,(select name from proimage where idprod=p.id)
             * from product p
             * where p.statusprod=1
             *
             */
            IQueryable <ModelView.ProductView> result = (from prod in db.Products
                                                         where prod.StatusProd == 1
                                                         select new ModelView.ProductView
            {
                id = prod.id,
                name = prod.name,
                description = prod.description,
                IDC = prod.IDC ?? 0,
                price = prod.price,
                stock = prod.stock,
                picture = (prod.ProImages.Where(d => d.StatusIMG == 1 && d.IDP == prod.id).FirstOrDefault()).Name,
                CateName = prod.Category.name
            }).OrderByDescending(prod => prod.id);

            return(result.ToList());
        }
Ejemplo n.º 13
0
        public JsonResult BindCity(Guid CountryId)
        {
            IEnumerable cityList = null;

            try
            {
                ShopOnlineEntities db = new ShopOnlineEntities();

                cityList = from p in db.Cities where p.CountryID == CountryId select p;
            }
            catch (Exception e)
            {
                throw e;
            }
            return(Json(new SelectList(cityList, "CityID", "NameCity"), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 14
0
        public static List <ModelView.CategoryView> GetListCateView()
        {
            db = new ShopOnlineEntities();
            var rs = db.Categories.Select(c => new ModelView.CategoryView
            {
                ID           = c.id,
                Name         = c.name,
                StatusCat    = c.StatusCat,
                ProductCount = c.Products.Where(d => d.IDC == c.id && d.StatusProd == 1).Select(d => d.id).Count(),
                DeleteStatus = !(
                    db.Products.Any(p => p.IDC == c.id)
                    )
            }).ToList();

            return(rs);
        }
Ejemplo n.º 15
0
        public static int AddProduct(ModelView.PView item)
        {
            db = new ShopOnlineEntities();
            Product pro = new Product
            {
                description = item.description,
                IDC         = item.IDC,
                name        = item.name,
                price       = item.price,
                StatusProd  = 1,
                stock       = item.stock
            };

            db.Products.Add(pro);
            db.SaveChanges();
            return(pro.id);
        }
Ejemplo n.º 16
0
        public static ModelView.ProductView get1Product(int id)
        {
            db = new ShopOnlineEntities();
            IQueryable <ModelView.ProductView> result = from p in db.Products
                                                        where p.id == id
                                                        select new ModelView.ProductView
            {
                id          = p.id,
                IDC         = p.Category.id,
                CateName    = p.Category.name,
                name        = p.name,
                price       = p.price,
                description = p.description,
                picture     = p.ProImages.Where(pi => pi.StatusIMG == 1).FirstOrDefault().Name,
                stock       = p.stock
            };

            return(result.FirstOrDefault());
        }
Ejemplo n.º 17
0
 public static ModelView.ProductView getDataByID(int id)
 {
     db = new ShopOnlineEntities();
     ModelView.ProductView rs = (from p in db.Products
                                 from i in db.ProImages
                                 where p.id == id && p.StatusProd == 1 && i.StatusIMG == 1 && i.IDP == p.id
                                 select new ModelView.ProductView
     {
         id = p.id,
         IDC = p.IDC ?? 0,
         CateName = p.Category.name,
         name = p.name,
         description = p.description,
         picture = i.Name,
         price = p.price,
         StatusProd = p.StatusProd,
         stock = p.stock
     }).FirstOrDefault();
     return(rs);
 }
Ejemplo n.º 18
0
        public static List <ModelView.ProductView> GetListPaging(int pageindex, int pagesize, int idc)
        {
            db = new ShopOnlineEntities();
            List <ModelView.ProductView> dt = (from a in db.Products
                                               from b in db.ProImages
                                               where a.id == b.IDP && b.StatusIMG == 1 && a.StatusProd == 1 && a.IDC == idc
                                               select new ModelView.ProductView
            {
                id = a.id,
                IDC = a.IDC ?? 0,
                CateName = a.Category.name,
                name = a.name,
                description = a.description,
                picture = b.Name,
                price = a.price,
                StatusProd = a.StatusProd,
                stock = a.stock
            }).OrderByDescending(a => a.id).Skip(pageindex * pagesize).Take(pagesize).ToList();

            return(dt);
        }
Ejemplo n.º 19
0
 public static bool checkMail(string emailWeb)
 {
     db = new ShopOnlineEntities();
     try
     {
         var a = db.WebUsers.Where(x => x.email == emailWeb).Count();
         if (a > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Ejemplo n.º 20
0
        public static bool updateInfo(ModelView.UserView item)
        {
            db = new ShopOnlineEntities();

            try
            {
                WebUser user1 = db.WebUsers.Find(item.id) as WebUser;
                user1.name     = item.name;
                user1.uAddress = item.uAddress;
                user1.pwd      = item.pwd;
                user1.phone    = item.phone;
                user1.zipcode  = item.zipcode;
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
Ejemplo n.º 21
0
        public static bool addFeedBack(ModelView.CommentView item)
        {
            db = new ShopOnlineEntities();
            try
            {
                Comment cm = new Comment
                {
                    feedback    = item.comment,
                    email       = item.email,
                    typeComment = 0,
                    typeFB      = item.typeFB
                };
                db.Comments.Add(cm);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
Ejemplo n.º 22
0
 public static bool updateProduct(ModelView.ProductView item, HttpPostedFileBase picture)
 {
     db = new ShopOnlineEntities();
     try
     {
         Product p = db.Products.Find(item.id) as Product;
         p.name        = item.name;
         p.price       = item.price;
         p.stock       = item.stock;
         p.description = item.description;
         //p.StatusProd = item.StatusProd
         db.SaveChanges();
         ProImage pi = db.ProImages.Where(pix => pix.IDP == p.id).FirstOrDefault() as ProImage;
         pi.Name = picture.FileName;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Ejemplo n.º 23
0
        public static ModelView.UserView loginUser(ModelView.UserView item)
        {
            db = new ShopOnlineEntities();
            try
            {
                WebUser user = db.WebUsers.Where(x => x.email == item.email).FirstOrDefault() as WebUser;
                if (user.ID > 0)
                {
                    item.pwd      = Decrypt(user.pwd);
                    item.id       = user.ID;
                    item.userType = user.usertype;
                    item.name     = user.name;
                    return(item);
                }
            }
            catch (Exception ex)
            {
                return(item);

                throw ex;
            }
            return(item);
        }
Ejemplo n.º 24
0
        public static bool addOderDt(ModelView.oderDetailView item)
        {
            db = new ShopOnlineEntities();
            try
            {
                OderDetail odt = new OderDetail
                {
                    IDO       = item.IDO,
                    IDP       = item.IDP,
                    quantity  = item.quantity,
                    total     = item.total,
                    StatusPay = false
                };
                db.OderDetails.Add(odt);
                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 25
0
        public ActionResult Login(User user)
        {
            using (ShopOnlineEntities db = new ShopOnlineEntities())
            {
                var usr  = db.Users.SingleOrDefault(u => u.UserName == user.UserName && u.PassWord == user.PassWord && u.Role == null);
                var usr1 = db.Users.SingleOrDefault(u => u.UserName == user.UserName && u.PassWord == user.PassWord && u.Role == 1 && u.IsDeleted == false);
                if (usr != null)
                {
                    Session["UserID"]   = usr.UserID.ToString();
                    Session["Role"]     = usr.Role.ToString();
                    Session["UserName"] = usr.UserName.ToString();
                    return(RedirectToAction("Index", "Home"));
                }

                if (usr1 != null)
                {
                    Session["UserID"]   = usr1.UserID.ToString();
                    Session["Role"]     = usr1.Role.ToString();
                    Session["UserName"] = usr1.UserName.ToString();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
Ejemplo n.º 26
0
        public static ModelView.PView GetProdByID(int id)
        {
            db = new ShopOnlineEntities();
            var rs = db.Products.Where(p => p.StatusProd == 1 && p.id == id).Select(p => new ModelView.PView
            {
                id          = p.id,
                IDC         = p.IDC ?? 0,
                CateName    = p.Category.name,
                description = p.description,
                name        = p.name,
                StatusProd  = p.StatusProd,
                price       = p.price,
                stock       = p.stock,
                image       = (db.ProImages.Where(i => i.IDP == p.id).Select(i => new ModelView.ProImageView
                {
                    ID = i.ID,
                    IDP = i.IDP ?? 0,
                    Name = i.Name,
                    StatusIMG = i.StatusIMG
                }).OrderBy(i => i.ID).Take(4).ToList())
            }).SingleOrDefault();

            return(rs);
        }
Ejemplo n.º 27
0
 //
 // GET: /Menu/
 public PartialViewResult MenuListResult()
 {
     _db = new ShopOnlineEntities();
     return(PartialView(_db.MenuLists.OrderBy(n => n.Order).ToList()));
 }
Ejemplo n.º 28
0
        public ActionResult EditProduct(FormCollection image)
        {
            ShopOnlineEntities blCarousel = new ShopOnlineEntities();

            Product product = new Product();

            product.ProductID         = Guid.Parse(image.Get("ProductID"));
            product.CategoryProductID = Guid.Parse(image.Get("CategoryProductID"));
            product.Name       = image.Get("Name").ToString();
            product.Desciption = image.Get("Desciption").ToString();
            product.Price      = Convert.ToDecimal(image.Get("Price"));
            product.CityID     = Guid.Parse(image.Get("CityID"));
            HttpPostedFileBase filebase = Request.Files["Image"];

            //Guid ShopID = Guid.Parse(image.Get("ShopID"));
            product.Count = Convert.ToInt32(image.Get("Count"));
            Product prot = db.Products.SingleOrDefault(n => n.ProductID == product.ProductID);

            if (ModelState.IsValid)
            {
                prot.ProductID    = product.ProductID;
                product.IsDeleted = prot.IsDeleted;
                // so sánh trên view và db theo producID
                if (prot.CategoryProductID != product.CategoryProductID)
                {
                    prot.CategoryProductID = product.CategoryProductID;
                }
                if (prot.Name != product.Name)
                {
                    prot.Name = product.Name;
                }
                if (prot.Desciption != product.Desciption)
                {
                    prot.Desciption = product.Desciption;
                }
                if (prot.Price != product.Price)
                {
                    prot.Price = product.Price;
                }
                if (prot.CityID != product.CityID)
                {
                    prot.CityID = product.CityID;
                }
                //else if (prot.ShopID != ShopID)
                //{
                //    prot.ShopID = ShopID;
                //}
                if (prot.Count != product.Count)
                {
                    prot.Count = product.Count;
                }

                //if (string.IsNullOrEmpty(filebase.FileName) != false)
                //{
                //    ViewBag.CityID = new SelectList(db.Cities, "CityID", "NameCity");
                //    ViewBag.CategoryProductID = new SelectList(db.CategoryProducts, "CategoryProductID", "Desciption");
                //    //return View(db.Products.SingleOrDefault(n => n.ProductID == product.ProductID));
                //}
                if (prot.Image != filebase.FileName && string.IsNullOrEmpty(filebase.FileName) == false)
                {
                    int    fileSize     = filebase.ContentLength;
                    byte[] readbytefile = new byte[fileSize];
                    filebase.InputStream.Read(readbytefile, 0, fileSize);
                    string file      = Path.GetFileNameWithoutExtension(filebase.FileName);
                    string extension = Path.GetExtension(filebase.FileName);
                    string fileName  = file + DateTime.Now.ToString("yymmssfff") + extension;
                    prot.Image = "~/Image/" + fileName;
                    fileName   = Path.Combine(Server.MapPath("~/Image/"), fileName);
                    filebase.SaveAs(fileName);
                }

                db.Update(prot);
                db.SaveChanges();
                ViewBag.CityID            = new SelectList(db.Cities, "CityID", "NameCity");
                ViewBag.CategoryProductID = new SelectList(db.CategoryProducts, "CategoryProductID", "Desciption");
            }

            return(View(db.Products.SingleOrDefault(n => n.ProductID == product.ProductID)));
        }
Ejemplo n.º 29
0
 public JsonResult TopHot()
 {
     _db = new ShopOnlineEntities();
     return(Json(_db.Products.Where(n => n.Active == true).OrderByDescending(n => n.CountOrder).Take(6).ToList(), JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 30
0
 public CategoryDAO()
 {
     db = new ShopOnlineEntities();
 }