public JsonResult ChangeStatus() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage(); res.Data = message; int tradeid = 0; int status = 1; int.TryParse(Request["trade_id"],out tradeid); int.TryParse(Request["status"],out status); User user = (User)Session["User"]; ShopManager shop = new ShopManager(user); try { if (shop.ChangeTradeStatus(tradeid, status)) { message.Status = "ok"; } else { message.Status = "failed"; } } catch (Exception ex) { message.Status = "failed"; message.Message = ex.Message; } return res; }
public JsonResult AddCategory() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage() { Status="ok"}; User user = (User)Session["User"]; ShopManager shopMgr = new ShopManager(user); string name = Request["name"]; string pid = Request["pid"]; int parentId = 0; int.TryParse(pid,out parentId); if (string.IsNullOrEmpty(name)) { message.Status = "failed"; message.Message = "类目名称不能为空"; } else { if (shopMgr.IsCategoryExist(parentId, name)) { message.Status = "failed"; message.Message = "类目名称已经存在"; res.Data = message; } else { Category cate = shopMgr.CreateCategory(parentId, name); message.Item = cate; res.Data = message; } } return res; }
public JsonResult Delete() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage() { Status = "ok" }; res.Data = message; User currentUser = (User)Session["User"]; if (currentUser == null) { message.Status = "failed"; message.Message = "没有登录不能删除图片"; return res; } AccountManager accountMgr=new AccountManager(); ShopManager shopMgr = new ShopManager(currentUser); Permission permission = shopMgr.Permission; if (permission.DELETE_PDT_IMAGE == 0) { message.Status = "failed"; message.Message = "没有权限删除图片"; return res; } int imgId = 0; int.TryParse(Request["image_id"],out imgId); if (shopMgr.DeleteImage(imgId, Request.PhysicalApplicationPath)) { message.Status = "ok"; } return res; }
public ActionResult AddProduct() { User user = (User)Session["User"]; ShopManager shopMgr = new ShopManager(user); List<Category> cates = shopMgr.GetCategories(); cates = (from c in cates where c.ParentID == 0 && c.Enabled==true select c).ToList<Category>(); ViewData["cate"] = cates; return View(); }
// // GET: /Home/ public ActionResult Index() { ShopManager manager = new ShopManager(null); int total = 0; int pageSize = 30; int pageIndex = 1; List<Product> pdts = manager.SearchProducts("", pageIndex, pageSize, out total); ViewBag.total = total; ViewBag.pageSize = pageSize; ViewBag.page = pageIndex; return View(pdts); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); User user = null; if (filterContext.HttpContext.Session["User"] == null) { user = (User)filterContext.HttpContext.Session["User"]; } ShopManager shopMgr = new ShopManager(user); filterContext.HttpContext.Session["category"] = shopMgr.GetCategories(); }
public JsonResult Categories() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage() { Status = "ok" }; User user = (User)Session["User"]; ShopManager shopMgr = new ShopManager(user); string pid = Request["parentId"]; int parentId = 0; int.TryParse(pid, out parentId); List<Category> cates = shopMgr.GetCategories(); cates = (from c in cates where c.ParentID == parentId select c).ToList<Category>(); res.Data=cates; return res; }
public ActionResult List(string cid,string page) { int categoryId = 0; int pageIndex = 1; int pageSize = 15; int.TryParse(cid, out categoryId); if (!string.IsNullOrEmpty(page)) { int.TryParse(page,out pageIndex); } ShopManager manager=new ShopManager(null); int total = 0; List<Product> pdts = manager.GetProducts(categoryId, pageIndex, pageSize, out total); ViewBag.cid = categoryId; ViewBag.total = total; ViewBag.pageSize = pageSize; ViewBag.page = pageIndex; return View(pdts); }
public ActionResult Detail(string id) { int productid = 0; int.TryParse(id, out productid); BProduct product = null; User user = null; if (Session["User"] != null) { user = (User)Session["User"]; } ShopManager manager = new ShopManager(user); product = manager.GetBProduct(productid); CorpInfo corpInfo = manager.GetCorpInfo(); ViewData["newpdt"] = manager.GetNewProducts(); ViewData["corpinfo"] = corpInfo; return View(product); }
// // GET: /Product/ public ActionResult Search() { string keyWord = Request["searchKey"]; ViewData["searchKey"] = keyWord; int pageIndex = 1; int pageSize = 15; if (!string.IsNullOrEmpty(Request["p"])) { int.TryParse(Request["p"], out pageIndex); } ShopManager manager=new ShopManager(null); int total = 0; List<Product> pdts = manager.SearchProducts(keyWord, pageIndex, pageSize, out total); ViewBag.total = total; ViewBag.pageSize = pageSize; ViewBag.page = pageIndex; return View("Search", pdts); }
public JsonResult AddToCart() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage(); res.Data = message; int pdtId = 0; int.TryParse(Request["product_id"],out pdtId); ShopManager manager = new ShopManager(null); Product pdt = manager.GetProduct(pdtId); if (pdt != null) { pdt.Quantity = 1; } List<Product> products = new List<Product>(); if (Session["cart"] == null) { Session["cart"] = products; } else { products = (List<Product>)Session["cart"]; } Product existed = (from p in products where p.ID == pdtId select p).FirstOrDefault<Product>(); if (existed == null) { products.Add(pdt); } else { existed.Quantity += 1; } message.Status = "ok"; return res; }
public ActionResult EditProduct(int id) { User user = (User)Session["User"]; ShopManager shopMgr = new ShopManager(user); List<Category> cates = shopMgr.GetCategories(); List<Category> ccates = null; Product product = shopMgr.GetProduct(id); List<Image> images = shopMgr.GetProductImages(id); Category category = (from c in cates where c.ID == product.CategoryID select c).FirstOrDefault<Category>(); int pcid = 0; if (category.ParentID > 0) { pcid = (int)category.ParentID; ccates = (from c in cates where c.ParentID == category.ParentID select c).ToList<Category>(); } cates = (from c in cates where c.ParentID == 0 select c).ToList<Category>(); ViewData["cate"] = cates; ViewData["ccate"] = ccates; ViewData["images"] = images; ViewBag.pcid = pcid; return View(product); }
public JsonResult UpdateProduct() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage() { Status = "ok", Message = "" }; User user = (User)Session["User"]; ShopManager manager = new ShopManager(user); Product product = new Product(); try { product.ID = int.Parse(Request["product_id"]); product.CategoryID = int.Parse(Request["category_id"]); product.Description = Request["description"]; if (Request["is_new"] == "1") { product.IsNew = 1; } if (Request["is_show"] == "1") { product.ShowFront = 1; } product.Picture = Request["pic"]; product.Price = double.Parse(Request["price"]); product.MarketPrice = double.Parse(Request["mprice"]); product.Quantity = int.Parse(Request["quantity"]); product.Title=Request["title"]; product.UserID = user.ID; string[] images=Request["images"].Split(','); int[] imgIds=new int[images.Length]; for (int i = 0; i < images.Length; i++) { imgIds[i] = int.Parse(images[i]); } if (product.ID == 0) { product.Created = anan.web.Util.DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); if (manager.CreateProduct(product, imgIds)) { message.Message = "产品添加成功"; message.Status = "ok"; } else { message.Status = "failed"; message.Message = "产品添加失败"; } } else { if (manager.UpdateProduct(product, imgIds)) { message.Message = "产品更新成功"; message.Status = "ok"; } else { message.Status = "failed"; message.Message = "产品更新失败"; } } res.Data = message; } catch (Exception ex) { message.Status = "failed"; res.Data = message; } return res; }
public JsonResult UpdateCategoryVisibility() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage(); res.Data = message; int cateid = 0; int.TryParse(Request["cid"],out cateid); User user = (User)Session["User"]; ShopManager account = new ShopManager(user); if (account.UpdateCategoryVisibility(cateid)) { message.Status = "ok"; } else { message.Status = "failed"; } return res; }
public ActionResult Order(int page) { User user = (User)Session["User"]; AccountManager manager = new AccountManager(); ShopManager shop = new ShopManager(user); int total = 0; int pageSize = 30; if (page <= 0) { page = 1; } List<Trade> trades = manager.GetTrades(0,0,0,0,out total,page,pageSize); ViewBag.page = page; ViewBag.pageSize = pageSize; ViewBag.total = total; List<Trade_Status> status = shop.GetStatus(); ViewData["tstatus"] = status; return View(trades); }
public JsonResult Upload() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage() { Status="ok"}; int len = Request.Files["Filedata"].ContentLength; string name = Request.Files["Filedata"].FileName; string uid = Request["authid"]; int user_id = 0; int.TryParse(uid,out user_id); if (user_id <= 0) { message.Status = "failed"; message.Message = "未登录用户不能上传图片"; res.Data = message; return res; } int size = len / (1024); if (size > 2 * 1024) { message.Status = "failed"; message.Message = "上传的文件大小不能超过3M"; } else { AccountManager accountMgr = new AccountManager(); User user = accountMgr.GetUser(user_id); ShopManager shopMgr = new ShopManager(user); string fileName = Path.GetFileName(name); string fileExt = Path.GetExtension(name); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; string dir1 = DateTime.Now.ToString("yyyy"); string dir2 = DateTime.Now.ToString("MM"); string dir3 = DateTime.Now.ToString("dd"); string dir4 = DateTime.Now.Hour.ToString(); string rootPath=Request.PhysicalApplicationPath+@"Content\Uploads\Images"; string absPath=@"/Content/Uploads/Images"; string location = Path.Combine(rootPath, dir1, dir2, dir3, dir4); absPath = absPath + "/" + dir1 + "/" + dir2 + "/" + dir3 + "/" + dir4; if (!Directory.Exists(location)) { Directory.CreateDirectory(location); } Image img = new Image(); img.UserID = user_id; img.ProductID = 0; img.Path = ""; img.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); img.FileName = name; shopMgr.CreateImage(img); System.Drawing.Image image = System.Drawing.Image.FromStream(Request.Files["Filedata"].InputStream); //if(image.Width>600){ // ImageUtil.ThumbPic(Request.Files["Filedata"].InputStream, 600, 0, location, fileName, true); //} ImageUtil.CutForCustom(Request.Files["Filedata"].InputStream, Path.Combine(location, newFileName), 600, 700, 80); if (System.IO.File.Exists(Path.Combine(location, newFileName))) { img.Path = absPath + "/" + newFileName; } message.Status = "ok"; message.Message = "succeed"; shopMgr.UpdateImage(img); message.Item = img; } res.Data = message; return res; }
public JsonResult RemoveFromCart() { JsonResult res = new JsonResult(); JsonMessage message = new JsonMessage(); res.Data = message; int pdtId = 0; int.TryParse(Request["product_id"], out pdtId); ShopManager manager = new ShopManager(null); Product pdt = manager.GetProduct(pdtId); List<Product> products = new List<Product>(); if (Session["cart"] != null) { products = (List<Product>)Session["cart"]; } Product existed = (from p in products where p.ID == pdtId select p).FirstOrDefault<Product>(); if (existed != null) { products.Remove(existed); } message.Status = "ok"; return res; }
public ActionResult Product(int page) { User user = (User)Session["User"]; ShopManager shopMgr = new ShopManager(user); int total=0; int pageSize = 30; if (page <= 0) { page = 1; } List<BProduct> products = shopMgr.GetBProducts(0,page,pageSize,out total); ViewBag.total=total; ViewBag.pageSize = pageSize; ViewBag.page = page; return View(products); }