Пример #1
0
        public ActionResult GetRating(string id)
        {
            TMDTModel db  = new TMDTModel();
            int       ids = int.Parse(id.Substring(0, id.IndexOf(",")));

            return(View(db.Accounts.Find(ids)));
        }
Пример #2
0
        public ActionResult GetData()
        {
            TMDTModel db           = new TMDTModel();
            var       ListCategory = new HierDAO().ListAll();

            ViewBag.Catlist  = new CategoryDAO().ListAll();
            ViewBag.HierList = ListCategory;
            return(PartialView());
        }
Пример #3
0
        public ActionResult Details(int id)
        {
            TMDTModel      db    = new TMDTModel();
            int?           idCat = db.Products.Find(id).CategoryID;
            List <Product> Lis   = db.Products.Where(s => s.CategoryID == idCat).ToList();
            Hierarchary    hier  = db.Hierarcharys.Find(idCat);

            ViewBag.Hier    = hier.Name;
            ViewBag.CatName = db.Categories.Find(hier.CategoryID).CategoryName;
            ViewBag.Same    = Lis;
            return(View(db.Products.Find(id)));
        }
Пример #4
0
 public ProductDAO()
 {
     db = new TMDTModel();
 }
Пример #5
0
 public OrderDAO()
 {
     db = new TMDTModel();
 }
Пример #6
0
 public BillDAO()
 {
     db = new TMDTModel();
 }
Пример #7
0
        public ActionResult ReturnSearch(string text, string category, string merchant, string pricetext1, string pricetext2, int?page, string currentFilter, string currentcategory, string currentmerchant, string curpricetext1, string curpricetext2)
        {
            TMDTModel db = new TMDTModel();

            db.Products.Load();
            var product = db.Products.Include(s => s.Category);

            if (text != null)
            {
                page = 1;
            }
            else
            {
                text = currentFilter;
            }
            ViewBag.CurrentFilter = text;
            if (category != null)
            {
                page = 1;
            }
            else
            {
                category = currentcategory;
            }
            ViewBag.CurrentCategory = category;
            if (merchant != null)
            {
                page = 1;
            }
            else
            {
                merchant = currentmerchant;
            }
            ViewBag.CurrentMerchant = merchant;
            if (pricetext1 != null)
            {
                page = 1;
            }
            else
            {
                pricetext1 = curpricetext1;
            }
            ViewBag.CurrentP1 = pricetext1;
            if (pricetext2 != null)
            {
                page = 1;
            }
            else
            {
                pricetext2 = curpricetext2;
            }
            ViewBag.CurrentP2 = pricetext2;
            if (!string.IsNullOrEmpty(text))
            {
                product = product.Where(i => i.ProductName.Contains(text));
            }
            if (!string.IsNullOrEmpty(merchant))
            {
                product = product.Where(i => i.Account.UserName.Contains(merchant));
            }
            if (!String.IsNullOrEmpty(category))
            {
                int lop = Convert.ToInt32(category);
                product = product.Where(i => i.CategoryID == lop);
            }
            if (!String.IsNullOrEmpty(pricetext1))
            {
                int price1 = int.Parse(pricetext1);
                int price2 = int.Parse(pricetext2);
                product = product.Where(i => i.Price >= price1 && i.Price <= price2);
            }
            product = product.OrderBy(i => i.ProductName);
            if (product.Count() > 0)
            {
                foreach (Product item in product)
                {
                    int i = item.Image.IndexOf("|");
                    item.Image = item.Image.Substring(0, i);
                }
            }
            int pageSize   = 8;
            int pageNumber = (page ?? 1);

            return(View(product.ToPagedList(pageNumber, pageSize)));
        }
Пример #8
0
        public JsonResult SendRating(string r, string s, int id, string url)
        {
            TMDTModel db        = new TMDTModel();
            int       autoId    = id;
            Int16     thisVote  = 0;
            Int16     sectionId = 0;

            Int16.TryParse(s, out sectionId);
            Int16.TryParse(r, out thisVote);
            if (autoId.Equals(0))
            {
                return(Json("Phần đánh giá không thể thực hiện."));
            }

            switch (s)
            {
            case "5":
                Account user = Session["User"] as Account;
                var     isIt = db.VoteModels.Where(m => m.BuyerID == user.AccountID && m.MerchantID == autoId).FirstOrDefault();
                if (isIt != null)
                {
                    // keep the school voting flag to stop voting by this member
                    HttpCookie cookie = new HttpCookie(url, "true");
                    Response.Cookies.Add(cookie);
                    return(Json("<br />Bạn đã đánh giá người bán này rồi."));
                }
                Account sch = db.Accounts.Where(sc => sc.AccountID == autoId).First();
                if (!sch.Equals(null))
                {
                    try
                    {
                        sch.Rating          = (double)(thisVote + sch.Rating * sch.NoRating) / (double)(sch.NoRating + 1);
                        sch.NoRating       += 1;
                        db.Entry(sch).State = EntityState.Modified;
                        db.SaveChanges();

                        VoteModel vm = new VoteModel()
                        {
                            BuyerID    = user.AccountID,
                            MerchantID = autoId,
                            NoVotes    = thisVote,
                        };

                        db.VoteModels.Add(vm);
                        db.SaveChanges();
                        HttpCookie cookie = new HttpCookie(url, "true");
                        Response.Cookies.Add(cookie);
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }
                }
                break;

            default:
                break;
            }
            return(Json("<br />Bạn đã đánh giá " + r + " sao. Cảm ơn bạn."));
        }
Пример #9
0
 public HierDAO()
 {
     db = new TMDTModel();
 }
Пример #10
0
 public AdminDAO()
 {
     db = new TMDTModel();
 }
Пример #11
0
 public AccountDAO()
 {
     db = new TMDTModel();
 }
Пример #12
0
        public string UpdateCart(List <cartitem> cart)
        {
            try
            {
                List <cartitem> oldcart = storeDB.ShoppingCartItems.Where(c => c.CartID == ShoppingCartId).ToList();
                string          s       = "";
                TMDTModel       db      = new TMDTModel();
                Product         album   = new Product();
                EmptyCart();
                for (int i = 0; i < cart.Count; i++)
                {
                    album = db.Products.Find(cart[i].ProductID);
                    if (album.Quantity > cart[i].Quantity)
                    {
                        cartitem cartitem = new cartitem
                        {
                            ItemID      = cart[i].ItemID,
                            Quantity    = cart[i].Quantity,
                            ProductID   = cart[i].ProductID,
                            CartID      = cart[i].CartID,
                            DateCreated = cart[i].DateCreated
                        };
                        storeDB.ShoppingCartItems.Add(cartitem);
                    }
                    else
                    {
                        cartitem cartitem = new cartitem
                        {
                            ItemID      = cart[i].ItemID,
                            Quantity    = oldcart.Where(x => x.ItemID.Equals(cart[i].ItemID)).SingleOrDefault().Quantity,
                            ProductID   = cart[i].ProductID,
                            CartID      = cart[i].CartID,
                            DateCreated = cart[i].DateCreated
                        };
                        storeDB.ShoppingCartItems.Add(cartitem);
                        s += "Số lượng sản phẩm " + album.ProductName + " Không đủ , ";
                    }
                }

                storeDB.SaveChanges();
                if (String.IsNullOrEmpty(s))
                {
                    return("Cập nhật thành công");
                }
                else
                {
                    return(s);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
Пример #13
0
 public CategoryDAO()
 {
     db = new TMDTModel();
 }