示例#1
0
        public ActionResult VeryAccount(int id)
        {
            bool Status = false;

            using (dotnetstorephoneEntities1 phone = new dotnetstorephoneEntities1())
            {
                var v = phone.users.Where(a => a.id == id).FirstOrDefault();
                System.Diagnostics.Debug.WriteLine("gggg" + v);
                if (v != null)
                {
                    v.activeFlag = 1;
                    v.createDate = DateTime.Now;
                    v.updateDate = DateTime.Now;
                    phone.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request!";
                }
            }

            ViewBag.Status = Status;
            return(View());
        }
示例#2
0
        public ProductDetail findProductDetailById(int id)
        {
            dotnetstorephoneEntities1 db = new dotnetstorephoneEntities1();

            ProductDetail pd = new ProductDetail(db.productdetails.Find(id));

            return(pd);
        }
        public int checkProductInStorage(int productDetailId)
        {
            dotnetstorephoneEntities1 db = new dotnetstorephoneEntities1();
            String         sql           = "select * from storage s where s.quantity>0 and s.productDetailId=" + productDetailId;
            List <storage> storages      = db.storages.SqlQuery(sql).ToList <storage>();

            return(storages.Count);
        }
示例#4
0
        public decimal getMinValue(int specID)
        {
            String sql = "select MIN(price) from productdetail where specId=" + specID;

            using (dotnetstorephoneEntities1 db = new dotnetstorephoneEntities1())
            {
                decimal minPrice = db.Database.SqlQuery <decimal>(sql).FirstOrDefault();
                return(minPrice);
            }
        }
示例#5
0
        public bool IsEmailExist(string email)
        {
            using (dotnetstorephoneEntities1 phone_Store = new dotnetstorephoneEntities1())
            {
                var v = phone_Store.users.Where(a => a.email == email).FirstOrDefault();


                return(v != null);
            }
        }
        public JsonResult listProductPagging()
        {
            dotnetstorephoneEntities1 db       = new dotnetstorephoneEntities1();
            List <product>            products = new List <product>();
            int limit = int.Parse(Request.QueryString["limit"]);

            System.Diagnostics.Debug.WriteLine(limit);
            db.Configuration.ProxyCreationEnabled = false;
            String         sql  = "SELECT * FROM product WHERE brandId=2 LIMIT " + limit + ",3";
            List <product> list = db.products.SqlQuery(sql.ToString()).ToList <product>();


            foreach (product product in list)
            {
                products.Add(product);
            }
            System.Diagnostics.Debug.WriteLine("Phân trang theo limit" + limit + " :" + products.Count());

            /*foreach(product product in list)
             * {
             *
             *
             *  html += " < div class="+"'col-lg-3 col-md-6'"+">";
             *  html += " < div class='single-product'>";
             *  html += " < div class='product-img'>";
             *  html += " < img src = '~/Content/client/img/product/"+ product.imgMain + "' height='266' width='266' />";
             *  html += " < div class='p_icon'>";
             *  html += " < a href = '@Url.Action('ProductDetail','ProductDetail', new { id = "+ product.id+" })'>";
             *  html += " <i class='ti-eye'></i>";
             *  html += " </a>";
             *  html += " < a href = '#'>";
             *  html += " <i class='ti-heart'></i>";
             *  html += " </a>";
             *  html += " < a href = '#'>";
             *  html += " <i class='ti-shopping-cart'></i>";
             *  html += " </a>";
             *  html += "</div>";
             *  html += "</div>";
             *  html += " <div class='product-btm'>";
             *  html += "<a href = '#' class='d-block'>";
             *  html += " <h4>"+product.name+"</h4>";
             *  html += " </a>";
             *  html += "  <div class='mt-3'>";
             *  html += "  <span class='mr-4 tien'>"+product.code+"</span>";
             *  html += "</div>";
             *  html += "</div>";
             *  html += "</div>";
             *  html += "</div>";
             *
             *
             * }*/


            return(Json(products, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public ActionResult Register([Bind(Exclude = "activeFlag")] user user)
        {
            bool   Status  = false;
            String Message = "";

            //model validation
            if (ModelState.IsValid)
            {
                #region //email is already Exits
                var isExist = IsEmailExist(user.email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion

                #region Generate activeFlag
                user.activeFlag = 0;

                user.createDate = DateTime.Now;
                user.updateDate = DateTime.Now;
                #endregion

                #region password hashing
                user.password = UtilPass.Hash(user.password);
                #endregion


                #region Save data database
                using (dotnetstorephoneEntities1 phone_Store = new dotnetstorephoneEntities1())
                {
                    phone_Store.users.Add(user);
                    phone_Store.SaveChanges();

                    //Send Email user
                    SendVerificationSendLinkEmail(user.email, user.id);
                    Message = "We have sent you a confirmation link at the email:" + user.email + ".Please confirm!";
                    Status  = true;
                    /*return RedirectToAction("Login", "MyUser");*/
                }
                #endregion
            }
            else
            {
                Message = "Invalid Request";
            }

            ViewBag.Message = Message;
            ViewBag.Status  = Status;

            return(View(user));
        }
        public ActionResult List()
        {
            using (dotnetstorephoneEntities1 db = new dotnetstorephoneEntities1())
            {
                List <product> products    = productDAO.getListProduct(0);
                List <product> productsAll = productDAO.getAllListProduct();
                double         pagging     = (double)productsAll.Count() / 3;
                double         tongsopage  = Math.Ceiling(pagging);

                ViewBag.ListPro    = products;
                ViewBag.tongsopage = tongsopage;
            }

            return(View());
        }
        public JsonResult getProduct()
        {
            int proId  = int.Parse(Request.QueryString["product_id"]);
            int specId = int.Parse(Request.QueryString["spec_id"]);

            List <Models.Entities.ProductDetail> productdetails = new List <Models.Entities.ProductDetail>();
            dotnetstorephoneEntities1            db             = new dotnetstorephoneEntities1();


            Product product = productDAO.findProductById(proId);
            Product pro     = new Product(product.id, product.name, product.description, product.imgMain,
                                          new Brand(product.brand.id, product.brand.name), new Category(product.category.id, product.category.name)
                                          );

            Models.Entities.ProductDetail productdetail;
            SpecDetail           specdetail;
            Spec                 spec;
            HashSet <SpecDetail> specdetails = new HashSet <SpecDetail>();

            foreach (Models.Entities.ProductDetail pd in product.productdetails)
            {
                if (pd.spec.id == specId)
                {
                    foreach (SpecDetail sd in pd.spec.specdetails)
                    {
                        specdetail = new SpecDetail(sd.id, sd.name, sd.value);
                        specdetails.Add(specdetail);
                    }

                    spec = new Spec(pd.spec.id, specdetails);
                    int status = 0;

                    if (checkProductInStorage(pd.id) > 0)
                    {
                        status = 1;
                    }

                    productdetail = new Models.Entities.ProductDetail(pd.id, spec, new Color(pd.color.id, pd.color.name),
                                                                      pd.price, pd.imgUrl, status);

                    productdetails.Add(productdetail);
                }
            }


            return(Json(productdetails, JsonRequestBehavior.AllowGet));
        }
示例#10
0
        public ActionResult ForgotPassWord(string email)
        {
            string message = "";
            bool   status  = false;

            using (dotnetstorephoneEntities1 p = new dotnetstorephoneEntities1())
            {
                var acc = p.users.Where(a => a.email == email).FirstOrDefault();
                if (acc != null)
                {
                }
                else
                {
                    message = "Account not found";
                }
            }
            return(View());
        }
        public ActionResult Create(int productId, String fullname, String email, String content)
        {
            if (ModelState.IsValid)
            {
                comment comment = new comment();
                comment.activeFlag = 1;
                comment.createDate = DateTime.Now;
                comment.updateDate = DateTime.Now;
                comment.productId  = productId;
                comment.fullname   = fullname;
                comment.email      = email;
                comment.content    = content;
                using (dotnetstorephoneEntities1 dt = new dotnetstorephoneEntities1())
                {
                    dt.comments.Add(comment);
                    dt.SaveChanges();
                    System.Diagnostics.Debug.WriteLine("gggg" + comment.content + comment.productId);
                }
            }

            return(Redirect("/chitiet/ProductDetail/" + productId));
        }
        public JsonResult searchProduct()
        {
            dotnetstorephoneEntities1 db       = new dotnetstorephoneEntities1();
            List <product>            products = new List <product>();

            String keys = (Request.QueryString["keys"]);

            db.Configuration.ProxyCreationEnabled = false;

            StringBuilder sql = new StringBuilder("select * from product p WHERE p.name LIKE");

            string[] listkeys = keys.Trim().Split(' ');
            if (listkeys.Length > 1)
            {
                sql.Append("'%").Append(listkeys[0]).Append("%'");
                for (int i = 1; i < listkeys.Length; i++)
                {
                    sql.Append(" AND name LIKE " + "'%").Append(listkeys[i]).Append("%'");
                }
            }
            else
            {
                sql.Append("'%").Append(keys).Append("%'");
            }

            List <product> list = db.products.SqlQuery(sql.ToString()).ToList <product>();


            foreach (product product in list)
            {
                products.Add(product);
                System.Diagnostics.Debug.WriteLine("Tên sản phẩm có trong database :" + product.name);
            }

            System.Diagnostics.Debug.WriteLine("Số lượng :" + products.Count());
            return(Json(products, JsonRequestBehavior.AllowGet));
        }
示例#13
0
        public ActionResult SingleBlog()
        {
            dotnetstorephoneEntities1 phone_Store = new dotnetstorephoneEntities1();

            return(View());
        }
示例#14
0
        public ActionResult Login(UserLogin userLogin, string ReturnUrl = "")
        {
            #region encode

            /* string message = "";
             * if (ModelState.IsValid)
             * {
             *   using (phone_storeEntities ps = new phone_storeEntities())
             *   {
             *       string password = UtilPass.Hash(userLogin.Password);
             *       var v = ps.users.Where(a => a.username.Equals(userLogin.Username) && a.password.Equals(password)&& a.activeFlag==1).FirstOrDefault();
             *
             *       if (v != null)
             *       {
             *           FormsAuthentication.SetAuthCookie(v.username, userLogin.RememberMe);
             *           if (Url.IsLocalUrl(ReturnUrl))
             *           {
             *
             *               return Redirect(ReturnUrl);
             *           }
             *           else
             *           {
             *               int timeout = userLogin.RememberMe ? 525600 : 20;
             *               var ticket = new FormsAuthenticationTicket(userLogin.Username, userLogin.RememberMe, timeout);
             *               string encryted = FormsAuthentication.Encrypt(ticket);
             *               var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryted);
             *               cookie.Expires = DateTime.Now.AddMinutes(timeout);
             *               cookie.HttpOnly = true;
             *               Response.Cookies.Add(cookie);
             *               return RedirectToAction("Index", "Home");
             *           }
             *       }
             *       else
             *       {
             *           message = "Account does not exist!";
             *       }
             *   }
             * }
             * else
             * {
             *   message = "Please enter username and password!";
             * }
             * ViewBag.Message = message;*/
            #endregion
            string message = "";
            //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa phân quyền
            if (ModelState.IsValid)
            {
                string password   = UtilPass.Hash(userLogin.Password);
                var    isValiUser = Membership.ValidateUser(userLogin.Username, password);


                dotnetstorephoneEntities1 p = new dotnetstorephoneEntities1();
                var roles = (from a in p.roles
                             join b in p.roleusers on a.id equals b.roleId
                             join c in p.users on b.userId equals c.id
                             where c.username.Equals(userLogin.Username)
                             select a.roleName).ToArray <string>();



                foreach (string i in roles)
                {
                    if (isValiUser)
                    {
                        FormsAuthentication.SetAuthCookie(userLogin.Username, userLogin.RememberMe);

                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            if (i.Contains("Admin"))
                            {
                                return(RedirectToAction("Index", "Admin/HomeAdmin"));
                            }

                            /*if (i.Equals("AdminProduct"))
                             * {
                             *  return RedirectToAction("add_Product", "Admin/HomeAdmin");
                             * }*/
                        }
                    }
                    else
                    {
                        message = " Invalid Request! Your account is not activated yet.Please check your Email";
                    }
                }
                if (isValiUser)
                {
                    FormsAuthentication.SetAuthCookie(userLogin.Username, userLogin.RememberMe);
                    if (Url.IsLocalUrl(ReturnUrl))
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    message = " Invalid Request! Your account is not activated yet.Please check your Email";
                }
            }

            ViewBag.Message = message;
            ModelState.Remove("password");
            return(View());
        }