Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        public JsonResult CancelTrade()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            User user = (User)Session["User"];
            res.Data = message;
            int trade_id = 0;
            int.TryParse(Request["trade_id"],out trade_id);
            try
            {
                AccountManager manager = new AccountManager();
                manager.CancelTrade(trade_id, user.ID);
                message.Status = "ok";
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }
            return res;
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 public JsonResult CheckNick()
 {
     JsonResult res = new JsonResult();
     JsonMessage message = new JsonMessage();
     string nickName = Request["nickName"];
     AccountManager am = new AccountManager();
     User user = (User)Session["User"];
     if (!string.IsNullOrEmpty(nickName))
     {
         bool existed = am.CheckNickIsUsed(nickName,user.ID);
         if (existed)
         {
             message.Status = "failed";
             message.Message = "此昵称已经被使用";
         }
         else
         {
             message.Status = "ok";
         }
     }
     res.Data = message;
     return res;
 }
Exemplo n.º 8
0
        public JsonResult SubmitOrder()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;

            int addressId = 0;
            int.TryParse(Request["address"],out addressId);
            string description = "";
            if (!string.IsNullOrEmpty(Request["description"])) {
                description = Request["description"];
            }

            List<Product> products = (List<Product>)Session["cart"];

            User user = (User)Session["User"];
            AccountManager manager = new AccountManager();
            if (manager.SubmitOrder(user.ID, addressId, products, description))
            {
                message.Status="ok";
                Session["cart"] = null;
            }else
            {
                message.Status="failed";
            }

            return res;
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        public JsonResult IncreaseQuantity()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;

            int num = 0;
            int pid = 0;
            int.TryParse(Request["num"],out num);
            int.TryParse(Request["product_id"], out pid);
            List<Product> products = new List<Product>();

            if (Session["cart"] != null)
            {
                products = (List<Product>)Session["cart"];
            }

            Product existed = (from p in products where p.ID == pid select p).FirstOrDefault<Product>();

            if (existed != null)
            {
                existed.Quantity += num;
            }
            message.Status = "ok";

            return res;
        }
Exemplo n.º 11
0
        public JsonResult GetCommonDistrict()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;
            AccountManager manager = new AccountManager();

            int pid = 0;
            int.TryParse(Request["pid"],out pid);

            List<Common_district> diss = manager.GetCommonDistricts(pid);
            message.Status = "ok";
            message.Item = diss;
            return res;
        }
Exemplo n.º 12
0
        public JsonResult DeleteAddress()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;
            AccountManager manager = new AccountManager();
            User user = (User)Session["User"];
            int id = 0;

            int.TryParse(Request["id"], out id);

            if (manager.DeleteAddress(id,user.ID))
            {
                message.Status = "ok";
            }
            else
            {
                message.Status = "failed";
                message.Message = "地址删除失败";
            }

            return res;
        }
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 14
0
        public JsonResult UpdatePassword()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;
            string password=Request["password"];
            User user = (User)Session["User"];
            if (user == null)
            {
                message.Status = "failed";
                message.Message = "更新失败";
                return res;
            }
            user.Password = anan.web.Util.Encrypt.MD5(password);
            AccountManager manager = new AccountManager();

            if (manager.UpdateUser(user))
            {
                message.Status = "ok";
            }
            else
            {
                message.Status = "failed";
                message.Message = "更新失败";
            }
            res.Data = message;

            return res;
        }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
0
        public JsonResult SaveSiteInfo()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage() {  Status="ok",Message=""};
            User user = (User)Session["User"];
            BaseManager manager = new BaseManager(user);
            try
            {
                string title = Request["title"];
                string about = Request["about"];
                string contact = Request["contact"];
                string team = Request["team"];
                string shipping = Request["shipping"];
                string backsale=Request["backsale"];
                CorpInfo info = new CorpInfo();
                info.Team = team;
                info.About = about;
                info.Contact = contact;
                info.Title = title;
                info.BackSale = backsale;
                info.Shipping = shipping;
                manager.SetCorpInfo(info);
                res.Data = message;
            }
            catch (Exception ex)
            {

            }

            return res;
        }
Exemplo n.º 18
0
        public JsonResult UpdateUser()
        {
            JsonResult res = new JsonResult();
            string nick = Request["nickName"];
            string birthday = Request["birthday"];
            string gendar = Request["gendar"];
            string pid = Request["province"];
            string cid = Request["city"];
            string did = Request["district"];
            int province = 0;
            int city = 0;
            int district = 0;
            int.TryParse(pid, out province);
            int.TryParse(cid, out city);
            int.TryParse(did, out district);

            User user = (User)Session["User"];
            user.NickName = nick;
            user.Gendar = short.Parse(gendar);
            user.Birthday = birthday;
            user.ProvinceID = province;
            user.CityID = city;
            user.DistrictID = district;
            AccountManager manager = new AccountManager();
            JsonMessage message = new JsonMessage();
            if (manager.UpdateUser(user))
            {
                message.Status = "ok";
            }
            else
            {
                message.Status="failed";
                message.Message = "更新失败";
            }
            res.Data = message;
            return res;
        }
Exemplo n.º 19
0
 public JsonResult CheckRegisterEmail()
 {
     JsonResult res = new JsonResult();
     string email=Request["email"];
     JsonMessage message = new JsonMessage();
     AccountManager am=new AccountManager();
     if (!string.IsNullOrEmpty(email))
     {
         bool existed = am.CheckEmailIsRegistered(email);
         if (existed)
         {
             message.Status = "failed";
             message.Message = "此邮件地址已经被注册";
         }
         else
         {
             message.Status = "ok";
         }
     }
     res.Data = message;
     return res;
 }
Exemplo n.º 20
0
        public JsonResult CheckPass()
        {
            JsonResult res = new JsonResult();
            User user = (User)Session["User"];
            JsonMessage message = new JsonMessage();
            res.Data = message;
            string pass = Request["password"];

            if (anan.web.Util.Encrypt.MD5(pass) != user.Password)
            {
                message.Status = "failed";
                message.Message = "旧密码错误";
            }
            else
            {
                message.Status = "ok";
            }
            return res;
        }
Exemplo n.º 21
0
        public JsonResult CreateAddress()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;

            int pid = 0;
            int cid = 0;
            int did = 0;
            string address = Request["address"];
            string person = Request["person"];
            string phone = Request["phone"];
            int.TryParse(Request["province"], out pid);
            int.TryParse(Request["city"], out cid);
            int.TryParse(Request["district"], out did);

            AccountManager manager = new AccountManager();
            User user =(User)Session["User"];

            if (manager.CreateAddress(user.ID, pid, cid, did, address, person, phone))
            {
                message.Status = "ok";
            }
            else {
                message.Status = "failed";
                message.Message = "地址创建失败";
            }

            return res;
        }