Beispiel #1
0
 //点赞、取消赞
 //userid为点赞人/取消赞人的ID号
 public JsonpResult OptIn(int tid, int userid, int point)
 {
     try
     {
         var territory = db.Territories.Find(tid);
         //territory.PraiseTimes += point;
         if (point == 1)
         {
             db.Praises.Add(new Praise()
             {
                 TId    = tid,
                 UserId = userid
             });
             db.SaveChanges();
         }
         else if (point == -1)
         {
             var praise = db.Praises.Single(x => x.TId == tid && x.UserId == userid);
             db.Praises.Attach(praise);
             db.Praises.Remove(praise);
             db.SaveChanges();
         }
         territory.PraiseTimes = db.Praises.Where(x => x.TId == tid).ToList().Count;
         db.SaveChanges();
         return(this.Jsonp(this.WrapNoKey("OK")));
     }
     catch
     {
         return(this.Jsonp(this.WrapNoKey("Error")));
     }
 }
Beispiel #2
0
 //用户添加自己要卖的二手商品信息,发布
 public JsonpResult AddProduct(int userid, string pdtitle, int pdtype, string pdprice, string pdmsg)
 {
     try
     {
         db.Products.Add(new Product()
         {
             PdTitle     = pdtitle,
             PdType      = (GoodsType)pdtype,
             PdPrice     = decimal.Parse(pdprice),
             PdMsg       = pdmsg,
             LaunchTime  = DateTime.Now.ToString(),
             IsOnShelves = true
         });
         db.SaveChanges();
         //找到最后一个product的id号,填入关联表/
         var pdid = db.Products.AsEnumerable().Last().Id;
         db.UserProducts.Add(new UserProduct()
         {
             UserId = userid,
             PdId   = pdid
         });
         db.SaveChanges();
         return(this.Jsonp(this.WrapNoKey(pdid)));
     }
     catch
     {
         return(this.Jsonp(this.WrapNoKey("add product failed")));
     }
 }
        public ActionResult Create([Bind(Include = "Id,StudentId,StudentClass,StudentName")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public JsonpResult Register(string username, string pswd, string userno, string tel, string sign, string usericon)
        {
            var judge  = db.Students.Where(x => x.StudentId == userno && x.StudentName == username);
            var isUReg = db.Users.Where(x => x.UserNo == userno);

            ////判断学生表中是否有相应学生:必须保证姓名和学号信息与学生表中信息一致
            //if (judge == null || judge.Count() < 1)
            //{
            //    return this.Jsonp(this.WrapNoKey("Invalid userno or username"));
            //}
            //判断当前注册用学号是否已被注册
            if (isUReg != null && isUReg.Count() >= 1)
            {
                return(this.Jsonp(this.WrapNoKey("Registered")));
            }
            else
            {
                db.Users.Add(new User()
                {
                    UserName = username,
                    Pswd     = pswd,
                    UserNo   = userno,
                    Tel      = tel,
                    Sign     = sign,
                    UserIcon = usericon,
                    Sex      = (Gender)1
                });
                db.SaveChanges();
                var user = _userService.GetUserByUserNo(userno);
                return(this.Jsonp(this.WrapNoKey(user.Id)));
            }
        }
Beispiel #5
0
        //收藏商品
        public JsonpResult CollectProduct(int userid, int pdid)
        {
            var judge = db.ProductWishlists.Where(x => x.UserId == userid && x.PdId == pdid);

            if (judge == null || judge.Count() < 1)
            {
                db.ProductWishlists.Add(new ProductWishlist()
                {
                    UserId = userid,
                    PdId   = pdid
                });
                db.SaveChanges();
                return(this.Jsonp(this.WrapNoKey("OK")));//要不要返回id之类的信息?
            }
            else
            {
                return(this.Jsonp(this.WrapNoKey("Collected")));
            }
        }
 //添加地盘里的新纪录
 public JsonpResult AddTerritory(int userid, string site, string remark)
 {
     try
     {
         db.Territories.Add(new Territory()
         {
             UserId = userid,
             Site   = site,
             Remark = remark,
             Time   = DateTime.Now.ToString("yyyy/MM/dd")
         });
         db.SaveChanges();
         var tid = db.Territories.AsEnumerable().Last().Id;
         return(this.Jsonp(this.WrapNoKey(tid)));
     }
     catch
     {
         return(this.Jsonp(this.WrapNoKey("add territory fail")));
     }
 }
        public void Test(string base64)
        {
            int id = 9;

            byte[]       bytes     = Convert.FromBase64String(base64);
            MemoryStream memStream = new MemoryStream(bytes);
            Bitmap       bmp       = new Bitmap(memStream);

            string date   = DateTime.Now.ToString("yyyyMMdd");
            string uppath = Server.MapPath("~/Image/") + date + "\\";

            //如果不存在,就新建文件夹
            if (Directory.Exists(uppath) == false)
            {
                Directory.CreateDirectory(uppath);
            }
            //普通二手商品
            var product = db.Products.Find(id);
            //图片命名
            string image = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + id + product.PdType + ".jpg";
            //图片存储路径
            string path = uppath + image;

            bmp.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
            string ipv4 = "";

            System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
            foreach (IPAddress ip in addressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    ipv4 = ip.ToString();
                }
            }
            //URL获取图片时用的绝对路径,存储在数据库中
            string savepath = ipv4 + "/Image/" + date + "/" + image;

            product.PdImage = savepath;
            db.SaveChanges();
            memStream.Close();
        }
Beispiel #8
0
        //duration:持续时间(单位:天)
        public JsonpResult AddAuction(int userid, string auctitle, int auctype,
                                      int isnew, decimal startingprice, decimal range, string aucmsg, int duration)
        {
            bool NewOrOld;

            if (isnew == 0)
            {
                NewOrOld = false;            //非新
            }
            else
            {
                NewOrOld = true; //全新
            }
            try
            {
                db.Auctions.Add(new Auction()
                {
                    AucTitle           = auctitle,
                    AucType            = (GoodsType)auctype,
                    IsNew              = NewOrOld,
                    StartingPrice      = startingprice,
                    PriceIncreaseRange = range,
                    AucMsg             = aucmsg,
                    StartTime          = DateTime.Now,
                    EndTime            = DateTime.Now.AddDays(duration).ToString("yyyy/MM/dd HH:mm:ss"),
                    NewPrice           = startingprice,
                    IsOnShelves        = true
                });
                db.SaveChanges();
                var aucid = db.Auctions.AsEnumerable().Last().Id;
                db.UserAuctions.Add(new UserAuction()
                {
                    UserId = userid,
                    AucId  = aucid
                });
                db.SaveChanges();
                return(this.Jsonp(this.WrapNoKey(aucid)));
            }
            catch
            {
                return(this.Jsonp(this.WrapNoKey("add auction failed")));
            }
        }
Beispiel #9
0
        //买家加价
        //拍卖品表中最新价格、买家id更新
        //拍卖品被自动添加到买家收藏夹中
        public JsonpResult AddPrice(int buyerid, int aucid, decimal newprice)
        {
            var sailerid = db.UserAuctions.Single(x => x.AucId == aucid).UserId;

            if (buyerid == sailerid)
            {
                return(this.Jsonp(this.WrapNoKey("cannot buy own auction")));
            }
            var auction = db.Auctions.Find(aucid);

            //判断买家加的价格是否大于拍卖品表中的newprice,若低于,说明有信息延时,提示买家重新加价
            if (newprice < auction.NewPrice)
            {
                return(this.Jsonp(this.WrapNoKey("newprice is lower")));
            }
            else
            {
                auction.NewPrice = newprice;
                auction.Buyerid  = buyerid;
                db.SaveChanges();
            }

            var isAuctionExist = db.AuctionWishlists.Where(x => x.UserId == buyerid && x.AucId == aucid);

            if (isAuctionExist == null || isAuctionExist.Count() < 1)
            {
                db.AuctionWishlists.Add(new AuctionWishlist()
                {
                    UserId      = buyerid,
                    AucId       = aucid,
                    NewAucPrice = newprice
                });
                db.SaveChanges();
            }
            else
            {
                db.AuctionWishlists.Single(x => x.UserId == buyerid && x.AucId == aucid).NewAucPrice = newprice;
                db.SaveChanges();
            }
            return(this.Jsonp(this.WrapNoKey("OK")));
        }