Example #1
0
        //前21天每天发布的捐赠物品数
        public JsonResult NumbersStatis()
        {
            dynamic        sp;
            List <dynamic> LL = new List <dynamic>();
            List <string>  x  = new List <string>();
            List <int>     y  = new List <int>();

            using (SSDBEntities db = new SSDBEntities())
            {
                for (int day = -20; day <= 0; day++)
                {
                    var LastDay     = DateTime.Now.AddDays(day);
                    var numOfThings = db.Things.Where(xt => xt.ReleaseTime.Value.Day == LastDay.Day).Count();
                    x.Add(DateTime.Now.AddDays(day).ToString("MM-dd"));
                    y.Add(numOfThings);
                }
            }
            sp      = new ExpandoObject();
            sp.type = "line";
            sp.data = y.ToArray();
            LL.Add(sp);
            return(Json(new
            {
                legend = new { data = new string[] { "物品数" } },
                xAxis = new { data = x.ToArray() },
                Series = JsonConvert.SerializeObject(LL)
            },
                        JsonRequestBehavior.AllowGet));
        }
Example #2
0
        //单件物品的评价雷达图
        public JsonResult CommentStatis(int thingId, int receiverId)
        {
            dynamic        indicator;
            List <dynamic> cators = new List <dynamic>();
            List <int>     values = new List <int>();

            using (SSDBEntities db = new SSDBEntities())
            {
                var c = db.Comments.Where(x => x.ReceiverId == receiverId && x.ThingId == thingId).FirstOrDefault();
                values.Add(c.NewScore.Value);
                values.Add(c.SimilarScore.Value);
                values.Add(c.UsefulScore.Value);
                values.Add(c.SpeedScore.Value);
                values.Add(c.BeautifulScore.Value);
            }
            foreach (var s in Scores)
            {
                indicator      = new ExpandoObject();
                indicator.name = s;
                indicator.max  = 5;
                cators.Add(indicator);
            }

            return(Json(new
            {
                Indicator = JsonConvert.SerializeObject(cators),
                SeriesData = values.ToArray()
            },
                        JsonRequestBehavior.AllowGet));
        }
        public ActionResult Login(LoginViewModel model)
        {
            //模型错误返回错误模型的Login视图
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //获取登录表单的用户名和密码
            string username = model.Username;
            string password = model.Password;

            //查询用户名和密码
            using (SSDBEntities db = new SSDBEntities())
            {
                //第一个和username匹配的Users元组
                var User = db.Users.Where(u => u.Username == username && u.Password == password).FirstOrDefault();
                if (User == null)//如果没找到对应Users,说明登录信息有误,返回登陆失败报错
                {
                    ModelState.AddModelError("", "登录失败");
                    return(View(model));
                }
                else//如果找到Users,给Session赋值
                {
                    HttpContext.Session["usrName"] = User.Username;
                    HttpContext.Session["usrId"]   = User.UserId;
                    HttpContext.Session["isAdmin"] = User.IsAdmin;
                }
            }
            //登录成功后跳转至用户主页
            return(RedirectToAction("Index", "User"));
        }
Example #4
0
        // GET: 查看待审核的受助请求列表
        // 修改时间: 2019年5月3日 15点06分
        public ActionResult CheckQuests(int currentPage = 1)
        {
            //新建视图模型列表
            var res = new List <QuestsListViewModel>();

            using (SSDBEntities db = new SSDBEntities())
            {
                //所有待审核的受助请求
                var qs = db.Quests.Where(x => x.Status == "正在审核中");
                //1.分页
                int totalThings = qs.Count();                                             //总共条目数目
                ViewBag.totalPages = (int)Math.Ceiling(totalThings / (double)numPerPage); //总共页数
                int start = (currentPage - 1) * numPerPage;                               //开始的条目
                qs = qs.OrderByDescending(x => x.ReleaseTime).Skip(start).Take(numPerPage);
                ViewBag.currentPage = currentPage;
                //给视图模型赋值
                foreach (var q in qs)
                {
                    //新建一个视图模型并赋值
                    var tmp = new QuestsListViewModel();
                    tmp.Quest = q;
                    //添加到列表中
                    res.Add(tmp);
                }
            }
            return(View(res));
        }
Example #5
0
        public ActionResult ThingsDetail(int id, string action)
        {
            using (SSDBEntities db = new SSDBEntities())
            {
                //找出对应id的捐赠物品
                Things t = db.Things.Where(x => x.Id == id).FirstOrDefault();
                switch (action)
                {
                case "删除":
                    //修改捐赠者信誉评价
                    if (t.Status == "等待受助中")
                    {
                        var tu = db.Assess.Where(x => x.UserId == t.DonatorId).FirstOrDefault();
                        tu.CreditPoint    -= 2;
                        tu.CreditLevel     = CreditFunction.GetCreditLevel(tu.CreditPoint.Value);
                        db.Entry(tu).State = EntityState.Modified;
                    }
                    //移除Things元组
                    db.Things.Remove(t);
                    db.SaveChanges();
                    return(RedirectToAction("MyThingsList"));

                case "返回":
                    //跳转至“我的捐赠物品”
                    return(RedirectToAction("MyThingsList"));;
                }
                return(View(t));
            }
        }
        public ActionResult UploadComment(UploadCommentViewModel model, int id)
        {
            int usrId = (int)HttpContext.Session["usrId"];

            if (ModelState.IsValid)
            {
                using (SSDBEntities db = new SSDBEntities())
                {
                    Comments c = new Comments();
                    c.CommentTime    = DateTime.Now;
                    c.NewScore       = model.NewScore;
                    c.ReceiverId     = usrId;
                    c.SimilarScore   = model.SimilarScore;
                    c.Text           = model.Text;
                    c.ThingId        = id;
                    c.UsefulScore    = model.UsefulScore;
                    c.BeautifulScore = model.BeautifulScore;
                    c.SpeedScore     = model.SpeedScore;
                    db.Comments.Add(c);

                    Assess a = db.Assess.Where(x => x.UserId == usrId).FirstOrDefault();
                    a.CreditPoint    += 1;
                    a.CreditLevel     = CreditFunction.GetCreditLevel(a.CreditPoint.Value);
                    db.Entry(a).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else
            {
                return(View(model));
            }
            return(RedirectToAction("MyQuestsList"));
        }
Example #7
0
        //全站所有发布的捐赠物品饼图
        public JsonResult CategoryStatis()
        {
            dynamic        sp;
            List <dynamic> LL      = new List <dynamic>();
            List <string>  legends = new List <string>();

            using (SSDBEntities db = new SSDBEntities())
            {
                var cates = db.Things
                            .GroupBy(x => x.Type)
                            .Select(gp => new
                {
                    type  = gp.Key,
                    count = gp.Count()
                });
                foreach (var c in cates)
                {
                    sp       = new ExpandoObject();
                    sp.value = c.count;
                    sp.name  = c.type;
                    LL.Add(sp);
                    legends.Add(c.type);
                }
            }
            return(Json(new
            {
                legend = new { data = legends },
                SeriesData = JsonConvert.SerializeObject(LL)
            },
                        JsonRequestBehavior.AllowGet));
        }
        public ActionResult QuestsDetail(int id, string action, int ThingId = 0)
        {
            using (SSDBEntities db = new SSDBEntities())
            {
                //找到id对应的Quests
                Quests q = db.Quests.Where(x => x.Id == id).FirstOrDefault();
                switch (action)
                {
                case "确认送达":
                    //找到匹配的ThingId
                    ThingsQuests tq  = db.ThingsQuests.Where(x => x.QuestId == id).FirstOrDefault();
                    var          tId = tq.ThingId;
                    //找到ThingId对应的Things
                    Things t = db.Things.Where(x => x.Id == tId).FirstOrDefault();
                    //修改Things状态
                    t.Status          = "捐赠已成功";
                    db.Entry(t).State = EntityState.Modified;
                    //修改Quests状态
                    q.Status          = "受助已成功";
                    db.Entry(q).State = EntityState.Modified;
                    //修改信誉评价
                    Assess tu = db.Assess.Where(x => x.UserId == t.DonatorId).FirstOrDefault();
                    Assess qu = db.Assess.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();
                    tu.CreditPoint += 5;
                    tu.CreditLevel  = CreditFunction.GetCreditLevel(tu.CreditPoint.Value);
                    tu.DonateNum++;
                    qu.CreditPoint += 1;
                    qu.CreditLevel  = CreditFunction.GetCreditLevel(qu.CreditPoint.Value);
                    qu.ReceiveNum++;
                    //执行操作
                    db.SaveChanges();
                    return(RedirectToAction("UploadComment", new { id = t.Id }));

                case "删除":
                    //修改受助方信誉评价
                    if (q.Status == "等待受助中")
                    {
                        var a = db.Assess.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();
                        a.CreditPoint    -= 2;
                        a.CreditLevel     = CreditFunction.GetCreditLevel(a.CreditPoint.Value);
                        db.Entry(a).State = EntityState.Modified;
                    }
                    //从数据库中移除Quests元组
                    db.Quests.Remove(q);
                    db.SaveChanges();
                    return(RedirectToAction("MyQuestsList"));

                case "评价物品":
                    return(RedirectToAction("UploadComment", new { id = ThingId }));

                case "返回":
                    //跳转至“我的受助请求”
                    return(RedirectToAction("MyQuestsList"));
                }
                return(View(q));
            }
        }
Example #9
0
 // GET: 打开首页界面
 public ActionResult Index()
 {
     using (SSDBEntities db = new SSDBEntities())
     {
         int cntUsers  = db.Users.Count();  //用户数量
         int cntThings = db.Things.Count(); //捐赠物品数量
         ViewBag.cntUsers  = cntUsers;
         ViewBag.cntThings = cntThings;
     }
     return(View());
 }
Example #10
0
        //爱心地图
        public JsonResult MapStatis()
        {
            dynamic        sp;
            List <dynamic> ps = new List <dynamic>();
            dynamic        nums;
            List <dynamic> numses = new List <dynamic>();
            int            maxNum = 0;

            using (SSDBEntities db = new SSDBEntities())
            {
                var ts = db.Things.Join(db.Users, t => t.DonatorId, u => u.UserId, (t, u) => new { t, u })
                         .GroupBy(x => x.u.Province)
                         .Select(gt => new
                {
                    province = gt.Key,
                    count    = gt.Count()
                });
                if (ts.Count() > 0)
                {
                    foreach (var p in Provinces)
                    {
                        sp      = new ExpandoObject();
                        sp.name = p;
                        var data = ts.Where(x => x.province == p).FirstOrDefault();
                        if (data != null)
                        {
                            sp.value = data.count;
                        }
                        else
                        {
                            sp.value = 0;
                        }
                        ps.Add(sp);
                    }

                    maxNum = ts.Max(x => x.count);
                }
            }
            int level = maxNum / 6 + 1;

            for (int i = 0; i < 6; i++)
            {
                nums       = new ExpandoObject();
                nums.start = i * level;
                nums.end   = i * level + level;
                numses.Add(nums);
            }
            return(Json(new
            {
                SeriesData = JsonConvert.SerializeObject(ps),
                Levels = JsonConvert.SerializeObject(numses)
            },
                        JsonRequestBehavior.AllowGet));
        }
Example #11
0
        // GET: 查看个人资料
        // 修改时间: 2019年5月26日 18点11分
        public ActionResult Manage()
        {
            //获取当前用户id
            int usrId = (int)HttpContext.Session["usrId"];

            using (SSDBEntities db = new SSDBEntities())
            {
                var u = db.Users.Where(x => x.UserId == usrId).FirstOrDefault();
                return(View(u));
            }
        }
Example #12
0
        // GET: 查看评论捐赠物品界面
        public ActionResult UploadComment(int id)
        {
            UploadCommentViewModel res = new UploadCommentViewModel();

            using (SSDBEntities db = new SSDBEntities())
            {
                Things t  = db.Things.Where(x => x.Id == id).FirstOrDefault();
                Users  tu = db.Users.Where(x => x.UserId == t.DonatorId).FirstOrDefault();
                res.Thing   = t;
                res.Donator = tu;
            }
            return(View(res));
        }
Example #13
0
        public ActionResult UploadQuests(UploadQuestsViewModel model, int?tId)
        {
            //获取当前用户的Id
            int usrId = (int)HttpContext.Session["usrId"];
            int qId   = 0;

            if (ModelState.IsValid)
            {
                //新建Quests
                Quests q = new Quests();
                q.ReceiverId  = usrId;
                q.Name        = model.qName;
                q.Type        = model.qType;
                q.Detail      = model.qDetail;
                q.ReleaseTime = DateTime.Now;
                q.Status      = tId != null ? "已接受受助" : "正在审核中";
                //向数据库新建元组,并获取新Quests的id
                using (SSDBEntities db = new SSDBEntities())
                {
                    db.Quests.Add(q);
                    db.SaveChanges();
                    qId = q.Id;
                }
                //如果当前有匹配捐赠物品,再新建一条匹配元组
                if (tId != null)
                {
                    //新建ThingsQuests
                    ThingsQuests tq = new ThingsQuests();
                    tq.ThingId = tId.Value;
                    tq.QuestId = qId;
                    tq.Time    = DateTime.Now;
                    //向数据库新建元组
                    using (SSDBEntities db = new SSDBEntities())
                    {
                        db.ThingsQuests.Add(tq);

                        Things t = db.Things.Where(x => x.Id == tId.Value).FirstOrDefault();
                        t.Status          = "已接受捐赠";
                        db.Entry(t).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                //提交成功,跳转至用户主页
                return(RedirectToAction("MyQuestsList"));
            }
            //模型报错,返回当前页面
            return(RedirectToAction("UploadQuests", new { id = tId }));
        }
Example #14
0
        public ActionResult Register(RegisterViewModel model)
        {
            //模型错误返回错误模型的Register视图
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //获取注册表单的用户名和密码
            string username = model.Username;
            string password = model.Password;

            using (SSDBEntities db = new SSDBEntities())
            {
                //若用户名重复,则返回用户名已注册报错
                if (db.Users.Where(x => x.Username == username).FirstOrDefault() != null)
                {
                    ModelState.AddModelError("", "用户名已注册");
                    return(View(model));
                }
                //新建Users元组
                var u = new Users();
                u.Username = username;
                u.Password = password;
                u.RegTime  = DateTime.Now;
                u.QQ       = model.QQ;
                u.Province = model.Province;
                u.School   = model.School;
                u.Sex      = model.Sex;
                u.IsAdmin  = model.isAdmin;
                u.Email    = model.Email;
                db.Users.Add(u);
                db.SaveChanges();

                //新建Assess元组
                var a = new Assess();
                a.UserId      = u.UserId;
                a.CreditLevel = 1;
                a.CheckedNum  = 0;
                a.CreditPoint = 0;
                a.DonateNum   = 0;
                a.ReceiveNum  = 0;
                a.Limit       = 1;
                db.Assess.Add(a);
                db.SaveChanges();
            }
            //注册成功跳转至登录页面
            return(RedirectToAction("Login"));
        }
Example #15
0
        // GET: 显示审核捐赠物品界面
        // 修改时间: 2019年5月3日 14点55分
        public ActionResult ThingsDetail(int id)
        {
            //新建视图模型
            DetailsViewModel res = new DetailsViewModel();

            using (SSDBEntities db = new SSDBEntities())
            {
                //找出对应id的捐赠物品
                Things t = db.Things.Where(x => x.Id == id).FirstOrDefault();
                res.Thing = t;

                //找出对应的捐赠者
                Users tu = db.Users.Where(x => x.UserId == t.DonatorId).FirstOrDefault();
                res.Donator = tu;
                return(View(res));
            }
        }
Example #16
0
        // GET: 查看信誉评价
        public ActionResult Credit()
        {
            //获取当前用户id
            int usrId = (int)HttpContext.Session["usrId"];
            //新建视图模型
            CreditViewModel res = new CreditViewModel();

            using (SSDBEntities db = new SSDBEntities())
            {
                Users  u = db.Users.Where(X => X.UserId == usrId).FirstOrDefault();
                Assess a = db.Assess.Where(x => x.UserId == usrId).FirstOrDefault();
                res.assess = a;
                res.QQ     = u.QQ;
                res.Email  = u.Email;
                return(View(res));
            }
        }
Example #17
0
        // GET: 显示审核受助请求界面
        // 修改时间: 2019年5月3日 14点57分
        public ActionResult QuestsDetail(int id)
        {
            //新建视图模型
            DetailsViewModel res = new DetailsViewModel();

            using (SSDBEntities db = new SSDBEntities())
            {
                //找出对应id的受助请求
                Quests q = db.Quests.Where(x => x.Id == id).FirstOrDefault();
                res.Quest = q;

                //找出对应的受助方
                Users qu = db.Users.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();
                res.Receiver = qu;
                return(View(res));
            }
        }
Example #18
0
        // GET: 显示受助请求详细信息
        // 修改时间: 2019年5月3日 13点02分
        public ActionResult QuestsDetail(int id)
        {
            //新建视图模型
            DetailsViewModel res = new DetailsViewModel();

            using (SSDBEntities db = new SSDBEntities())
            {
                //找出对应id的受助请求
                Quests q = db.Quests.Where(x => x.Id == id).FirstOrDefault();
                res.Quest = q;

                //找出对应的受助方
                Users qu = db.Users.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();
                res.Receiver = qu;
                //审核未通过的话还要获取审核信息
                if (q.Status == "审核未通过")
                {
                    Checks check = db.Checks.Where(x => x.Id == q.CheckId).FirstOrDefault();
                    res.Check = check;
                }
                //受助请求对应的捐赠物品..
                var ts = db.Things.Where(t =>
                                         (db.ThingsQuests.Where(qr => qr.QuestId == id)).Select(qrx => qrx.ThingId).Contains(t.Id));
                //..如果有的话
                if (ts.FirstOrDefault() != null)
                {
                    //捐赠物品信息
                    Things data = ts.FirstOrDefault();
                    res.Thing = data;

                    //捐赠者信息
                    Users tu = db.Users.Where(x => x.UserId == data.DonatorId).FirstOrDefault();
                    res.Donator = tu;

                    //评论信息
                    Comments c = db.Comments.Where(x => x.ThingId == data.Id).FirstOrDefault();
                    res.Comment = c;
                }
                return(View(res));
            }
        }
Example #19
0
        // GET: 显示捐赠物品详细信息
        // 修改时间: 2019年5月3日 15点10分
        public ActionResult ThingsDetail(int id)
        {
            //新建视图模型
            DetailsViewModel res = new DetailsViewModel();

            using (SSDBEntities db = new SSDBEntities())
            {
                //找出对应id的捐赠物品
                Things t = db.Things.Where(x => x.Id == id).FirstOrDefault();
                res.Thing = t;

                //找出对应的捐赠者
                Users tu = db.Users.Where(x => x.UserId == t.DonatorId).FirstOrDefault();
                res.Donator = tu;
                //审核未通过的话还要获取审核信息
                if (t.Status == "审核未通过")
                {
                    Checks check = db.Checks.Where(x => x.Id == t.CheckId).FirstOrDefault();
                    res.Check = check;
                }
                //捐赠物品对应的受助请求..
                var qs = db.Quests.Where(q =>
                                         (db.ThingsQuests.Where(tr => tr.ThingId == id)).Select(trx => trx.QuestId).Contains(q.Id));
                //..如果有的话
                if (qs.FirstOrDefault() != null)
                {
                    //受助请求信息
                    Quests data = qs.FirstOrDefault();
                    res.Quest = data;

                    //受助方信息
                    Users qu = db.Users.Where(x => x.UserId == data.ReceiverId).FirstOrDefault();
                    res.Receiver = qu;

                    //评论信息
                    Comments c = db.Comments.Where(x => x.ThingId == id).FirstOrDefault();
                    res.Comment = c;
                }
                return(View(res));
            }
        }
Example #20
0
 public ActionResult EditManage(EditManageViewModel model)
 {
     if (ModelState.IsValid)
     {
         //获取当前用户id
         int usrId = (int)HttpContext.Session["usrId"];
         using (SSDBEntities db = new SSDBEntities())
         {
             var u = db.Users.Where(x => x.UserId == usrId).FirstOrDefault();
             u.Province        = model.Province;
             u.School          = model.School;
             u.QQ              = model.QQ;
             u.Sex             = model.Sex;
             u.Email           = model.Email;
             db.Entry(u).State = EntityState.Modified;
             db.SaveChanges();
         }
         return(RedirectToAction("Manage"));
     }
     return(View(model));
 }
Example #21
0
        // GET: 以图搜图
        public ActionResult SearchThingsByImage(string hash, int currentPage = 1)
        {
            int usrId = (int)HttpContext.Session["usrId"];

            using (SSDBEntities db = new SSDBEntities())
            {
                var ts = db.Things.Where(x => x.DonatorId != usrId && x.Status == "物品闲置中");
                //1.地域
                var user = db.Users.Where(x => x.UserId == usrId).FirstOrDefault();
                var pro  = user.Province;
                var sch  = user.School;
                var ts_u = ts.Join(db.Users.Select(x => new { x.UserId, x.Province, x.School }), t => t.DonatorId, u => u.UserId, (t, u) => new { t, u });
                var tsu1 = ts_u.Where(o => o.u.Province.Contains(pro) && o.u.School.Contains(sch)).Select(n => new ThingsListViewModel {
                    Thing = n.t, prior = 300, similar = 0
                }).ToList();                                                                                                                                                               //同省同校
                var tsu2 = ts_u.Where(o => o.u.Province.Contains(pro) && !o.u.School.Contains(sch)).Select(n => new ThingsListViewModel {
                    Thing = n.t, prior = 200, similar = 0
                }).ToList();                                                                                                                                                                //同校不同省
                var tsu3 = ts_u.Where(o => !o.u.Province.Contains(pro)).Select(n => new ThingsListViewModel {
                    Thing = n.t, prior = 100, similar = 0
                }).ToList();                                 //不同省
                var ts_place = tsu1.Union(tsu2).Union(tsu3); //已转化为list的视图模型,之后关键字直接foreach匹配
                //2.相似度高置顶
                foreach (var t in ts_place)
                {
                    string tmp = t.Thing.ImageHash;
                    t.similar = ImageSimilarity(hash, tmp) * 100;
                }
                //3.分页
                int totalThings = ts.Count();                                             //总共条目数目
                ViewBag.totalPages = (int)Math.Ceiling(totalThings / (double)numPerPage); //总共页数
                int start = (currentPage - 1) * numPerPage;                               //开始的条目
                ts_place            = ts_place.OrderByDescending(x => x.similar).Skip(start).Take(numPerPage);
                ViewBag.currentPage = currentPage;
                ViewBag.hash        = hash;
                return(View(ts_place));
            }
        }
Example #22
0
        // GET: 显示上传物品的表单
        // 修改时间: 2019年5月8日 16点03分
        public ActionResult UploadThings(int?id)
        {
            if (id != null)
            {
                using (SSDBEntities db = new SSDBEntities())
                {
                    //查找id对应的受助请求
                    Quests q = db.Quests.Where(x => x.Id == id.Value).FirstOrDefault();
                    //查找受助方
                    Users qu = db.Users.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();
                    //新建视图模型
                    UploadThingsViewModel res = new UploadThingsViewModel();

                    //给视图模型赋值
                    res.Quest    = q;
                    res.Receiver = qu;
                    res.tName    = q.Name;
                    res.tType    = q.Type;
                    return(View(res));
                }
            }
            return(View());
        }
Example #23
0
 public ActionResult AdminCharts(AdminChartsViewModel model)
 {
     if (model.StartTime > model.EndTime)
     {
         ModelState.AddModelError("", "起始日期需早于结束日期");
         ViewBag.resData = "[]";
         return(View(model));
     }
     using (SSDBEntities db = new SSDBEntities())
     {
         var endtime = model.EndTime.AddDays(1);
         var lists   = db.ThingsQuests.Where(tq => tq.Time >= model.StartTime && tq.Time <= endtime)
                       .Join(db.Things.Select(x => new { x.Id, x.DonatorId, x.Type, x.Name }), tq => tq.ThingId, t => t.Id, (tq, t) => new { tq, t })
                       .Join(db.Quests.Select(y => new { y.Id, y.ReceiverId, y.Type, y.Name }), tq_t => tq_t.tq.QuestId, q => q.Id, (tq_t, q) => new { tq_t, q })
                       .Join(db.Users.Select(gz => new { gz.UserId, gz.Username }), tq_t_q => tq_t_q.tq_t.t.DonatorId, gu => gu.UserId, (tq_t_q, gu) => new { tq_t_q, gu })
                       .Join(db.Users.Select(rz => new { rz.UserId, rz.Username }), tq_t_q_gu => tq_t_q_gu.tq_t_q.q.ReceiverId, ru => ru.UserId, (tq_t_q_gu, ru) => new { tq_t_q_gu, ru })
                       .Select(m => new
         {
             ThingName    = m.tq_t_q_gu.tq_t_q.tq_t.t.Name,
             ThingType    = m.tq_t_q_gu.tq_t_q.tq_t.t.Type,
             GiverName    = m.tq_t_q_gu.gu.Username,
             QuestName    = m.tq_t_q_gu.tq_t_q.q.Name,
             QuestType    = m.tq_t_q_gu.tq_t_q.q.Type,
             ReceiverName = m.ru.Username,
             DealTime     = m.tq_t_q_gu.tq_t_q.tq_t.tq.Time
         })
                       .OrderBy(mx => mx.DealTime);
         var res = lists.ToList();
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         var resJson = serializer.Serialize(res);
         ViewBag.resData = resJson;
         ViewBag.Start   = localeDateTime(model.StartTime);
         ViewBag.End     = localeDateTime(model.EndTime);
         return(View(model));
     }
 }
Example #24
0
        int numPerPage = 12;//每页显示条目
        // GET: 显示发布请求的表单
        // 修改时间: 2019年5月8日 16点09分
        public ActionResult UploadQuests(int?id)
        {
            if (id != null)
            {
                using (SSDBEntities db = new SSDBEntities())
                {
                    //查找id对应的捐赠物品
                    Things t = db.Things.Where(x => x.Id == id.Value).FirstOrDefault();
                    //查找捐赠者
                    Users tu = db.Users.Where(x => x.UserId == t.DonatorId).FirstOrDefault();
                    //新建视图模型
                    UploadQuestsViewModel res = new UploadQuestsViewModel();

                    //给视图模型赋值
                    res.Thing   = t;
                    res.Donator = tu;
                    res.qName   = t.Name;
                    res.qType   = t.Type;
                    return(View(res));
                }
            }

            return(View());
        }
Example #25
0
        public ActionResult UploadThings(UploadThingsViewModel model, int?qId)
        {
            //获取当前用户的Id
            int usrId = (int)HttpContext.Session["usrId"];
            int tId   = 0;

            if (ModelState.IsValid)
            {
                //新建Things
                Things t = new Things();
                t.DonatorId   = usrId;
                t.Name        = model.tName;
                t.Type        = model.tType;
                t.Detail      = model.tDetail;
                t.ReleaseTime = DateTime.Now;
                t.Status      = qId != null ? "已接受捐赠" : "正在审核中";//如果当前有匹配受助请求,则跳过审核
                //文件存储到目录下
                foreach (var imgFile in model.Image)
                {
                    if (imgFile != null && imgFile.ContentLength > 0)
                    {
                        string extension = Path.GetExtension(imgFile.FileName);
                        if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                        {
                            string phicyPath = PublicFunction.GetPhicyPath();
                            //创建Upload文件夹,如果有则不创建
                            Directory.CreateDirectory(phicyPath);
                            //文件名与路径
                            var fileName = Path.GetFileName(imgFile.FileName);
                            var filePath = phicyPath + fileName;
                            //防止文件重名
                            while (System.IO.File.Exists(filePath))
                            {
                                Random rand = new Random();
                                fileName = rand.Next().ToString() + "-" + fileName;
                                filePath = phicyPath + fileName;
                            }
                            //存储文件到文件目录
                            imgFile.SaveAs(filePath);
                            //计算图片的哈希值
                            t.ImageHash = MainHash(filePath);
                            //保存提交的图片URL至数据库
                            t.ImageUrl = fileName;
                        }
                        else
                        {
                            ModelState.AddModelError("Image", "请上传正确格式的图片(.jpg .png .gif)");
                            return(View(model));
                        }
                    }
                }
                //向数据库新建元组,并获取新Things的id
                using (SSDBEntities db = new SSDBEntities())
                {
                    db.Things.Add(t);
                    db.SaveChanges();
                    tId = t.Id;
                }
                //如果当前有匹配受助请求,再新建一条匹配元组
                //并改变受助请求状态
                if (qId != null)
                {
                    //新建ThingsQuests
                    ThingsQuests tq = new ThingsQuests();
                    tq.ThingId = tId;
                    tq.QuestId = qId.Value;
                    tq.Time    = DateTime.Now;
                    //向数据库新建元组,改变受助请求状态
                    using (SSDBEntities db = new SSDBEntities())
                    {
                        db.ThingsQuests.Add(tq);

                        Quests q = db.Quests.Where(x => x.Id == qId.Value).FirstOrDefault();
                        q.Status          = "已接受受助";
                        db.Entry(q).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                //提交成功,跳转至用户主页
                return(RedirectToAction("MyThingsList"));
            }
            //模型报错,返回当前页面
            return(RedirectToAction("UploadThings", new { id = qId }));
        }
Example #26
0
        public ActionResult QuestsDetail(int id, string action, string reason)
        {
            int usrId = (int)HttpContext.Session["usrId"];

            using (SSDBEntities db = new SSDBEntities())
            {
                switch (action)
                {
                case "通过":
                    //新建Check元组
                    Checks c1 = new Checks();
                    c1.AdminId      = usrId;
                    c1.CheckedTime  = DateTime.Now;
                    c1.RefuseReason = "";
                    c1.Result       = 1;
                    db.Checks.Add(c1);
                    db.SaveChanges();
                    //找出对应id的受助请求
                    var q1 = db.Quests.Where(x => x.Id == id).FirstOrDefault();
                    //修改受助请求的状态
                    q1.Status          = "等待受助中";
                    q1.CheckId         = c1.Id;
                    db.Entry(q1).State = EntityState.Modified;

                    //修改受助方的信誉评价
                    var u1 = db.Assess.Where(x => x.UserId == q1.ReceiverId).FirstOrDefault();
                    u1.CreditPoint += 2;    //信誉点数+2
                    u1.CreditLevel  = CreditFunction.GetCreditLevel(u1.CreditPoint.Value);
                    u1.CheckedNum++;
                    db.Entry(u1).State = EntityState.Modified;
                    db.SaveChanges();


                    break;

                case "提交":
                    //新建Check元组
                    Checks c2 = new Checks();
                    c2.AdminId      = usrId;
                    c2.CheckedTime  = DateTime.Now;
                    c2.RefuseReason = reason;
                    c2.Result       = 0;
                    db.Checks.Add(c2);
                    db.SaveChanges();
                    //找出对应id的受助请求
                    var q2 = db.Quests.Where(x => x.Id == id).FirstOrDefault();
                    //修改受助请求的状态
                    q2.Status          = "审核未通过";
                    q2.CheckId         = c2.Id;
                    db.Entry(q2).State = EntityState.Modified;

                    //修改受助方的信誉评价
                    var u2 = db.Assess.Where(x => x.UserId == q2.ReceiverId).FirstOrDefault();
                    u2.CreditPoint    -= 2; //信誉点数-2
                    u2.CreditLevel     = CreditFunction.GetCreditLevel(u2.CreditPoint.Value);
                    db.Entry(u2).State = EntityState.Modified;
                    db.SaveChanges();

                    break;

                case "取消":
                    break;
                }
            }
            //跳转至请求列表
            return(RedirectToAction("CheckQuests"));
        }
Example #27
0
        public ActionResult ThingsDetail(int id, string action, string reason)
        {
            int usrId = (int)HttpContext.Session["usrId"];

            using (SSDBEntities db = new SSDBEntities())
            {
                switch (action)
                {
                case "通过":
                    //新建Check元组
                    Checks c1 = new Checks();
                    c1.AdminId      = usrId;
                    c1.CheckedTime  = DateTime.Now;
                    c1.RefuseReason = "";
                    c1.Result       = 1;
                    db.Checks.Add(c1);
                    db.SaveChanges();

                    //找出对应id的捐赠物品
                    var t1 = db.Things.Where(x => x.Id == id).FirstOrDefault();
                    //修改捐赠物品的状态
                    t1.Status          = "物品闲置中";
                    t1.CheckId         = c1.Id;
                    db.Entry(t1).State = EntityState.Modified;


                    //修改捐赠者的信誉评价
                    var u1 = db.Assess.Where(x => x.UserId == t1.DonatorId).FirstOrDefault();
                    u1.CreditPoint += 2;    //信誉点数+2
                    u1.CreditLevel  = CreditFunction.GetCreditLevel(u1.CreditPoint.Value);
                    u1.CheckedNum++;
                    db.Entry(u1).State = EntityState.Modified;
                    db.SaveChanges();


                    break;

                case "提交":
                    //新建Check元组
                    Checks c2 = new Checks();
                    c2.AdminId      = usrId;
                    c2.CheckedTime  = DateTime.Now;
                    c2.RefuseReason = reason;
                    c2.Result       = 0;
                    db.Checks.Add(c2);
                    db.SaveChanges();

                    //找出对应id的捐赠物品
                    var t2 = db.Things.Where(x => x.Id == id).FirstOrDefault();
                    //修改捐赠物品的状态
                    t2.Status          = "审核未通过";
                    t2.CheckId         = c2.Id;
                    db.Entry(t2).State = EntityState.Modified;

                    //修改捐赠者的信誉评价
                    var u2 = db.Assess.Where(x => x.UserId == t2.DonatorId).FirstOrDefault();
                    u2.CreditPoint    -= 2; //信誉点数-2
                    u2.CreditLevel     = CreditFunction.GetCreditLevel(u2.CreditPoint.Value);
                    db.Entry(u2).State = EntityState.Modified;
                    db.SaveChanges();

                    break;

                case "取消":
                    break;
                }
            }
            //跳转至物品列表
            return(RedirectToAction("CheckThings"));
        }
Example #28
0
        // GET: 查询其他用户的捐赠物品
        // 修改时间: 2019年5月9日 15点04分
        public ActionResult SearchThings(string keywords, int currentPage = 1)
        {
            //获取当前用户id
            int usrId = (int)HttpContext.Session["usrId"];

            List <string> sWords = new List <string>(); //近义词
            List <string> oWords = new List <string>(); //原词

            using (SSDBEntities db = new SSDBEntities())
            {
                //查找[其他用户的][闲置的]物品
                var ts = db.Things.Where(x => x.DonatorId != usrId && x.Status == "物品闲置中");
                //1.地域置顶
                var user = db.Users.Where(x => x.UserId == usrId).FirstOrDefault();
                var pro  = user.Province;
                var sch  = user.School;
                var ts_u = ts.Join(db.Users.Select(x => new { x.UserId, x.Province, x.School }), t => t.DonatorId, u => u.UserId, (t, u) => new { t, u });
                var tsu1 = ts_u.Where(o => o.u.Province.Contains(pro) && o.u.School.Contains(sch)).Select(n => new ThingsListViewModel {
                    Thing = n.t, prior = 300
                }).ToList();                                                                                                                                                  //同省同校
                var tsu2 = ts_u.Where(o => o.u.Province.Contains(pro) && !o.u.School.Contains(sch)).Select(n => new ThingsListViewModel {
                    Thing = n.t, prior = 200
                }).ToList();                                                                                                                                                   //同校不同省
                var tsu3 = ts_u.Where(o => !o.u.Province.Contains(pro)).Select(n => new ThingsListViewModel {
                    Thing = n.t, prior = 100
                }).ToList();                                 //不同省
                var ts_place = tsu1.Union(tsu2).Union(tsu3); //已转化为list的视图模型,之后关键字直接foreach匹配
                //2.获取同义分词 AI
                if (!string.IsNullOrEmpty(keywords))
                {
                    string data = TencentAI.tencentAI(keywords);
                    oWords = TencentAI.oriWords(data);
                    sWords = TencentAI.synWords(data);
                    //qs = qs.Where(x => x.Name.Contains(searchString));
                    //关键字匹配
                    foreach (var l in ts_place)
                    {
                        if (l.Thing.Name.Contains(keywords))
                        {
                            l.prior += 10;
                            continue;
                        }
                        for (int i = 0; i < oWords.Count; i++)
                        {
                            if (l.Thing.Name.Contains(oWords[i]))
                            {
                                l.prior += 5;
                                break;
                            }
                        }
                        for (int j = 0; j < sWords.Count; j++)
                        {
                            if (l.Thing.Name.Contains(sWords[j]))
                            {
                                l.prior += 1;
                                break;
                            }
                        }
                        if (l.prior % 100 == 0)
                        {
                            l.prior -= 1000;
                        }
                    }
                }
                ts_place = ts_place.Where(x => x.prior >= 0);
                //3.分页
                int totalThings = ts.Count();                                             //总共条目数目
                ViewBag.totalPages = (int)Math.Ceiling(totalThings / (double)numPerPage); //总共页数
                int start = (currentPage - 1) * numPerPage;                               //开始的条目
                ts_place             = ts_place.OrderByDescending(x => x.prior).Skip(start).Take(numPerPage);
                ViewBag.searchString = keywords;
                ViewBag.currentPage  = currentPage;
                return(View(ts_place));
            }
        }
Example #29
0
        // GET: 显示用户受助请求列表
        // 修改时间: 2019年5月23日 14点19分
        public ActionResult MyQuestsList(string keywords, string status, int currentPage = 1)
        {
            //获取当前用户id
            int usrId = (int)HttpContext.Session["usrId"];
            //新建视图模型列表
            var res = new List <QuestsListViewModel>();

            using (SSDBEntities db = new SSDBEntities())
            {
                //查找该用户发布的所有受助请求
                var qs = db.Quests.Where(x => x.ReceiverId == usrId);
                //1.按照关键字搜索
                if (keywords != null)
                {
                    qs = qs.Where(x => x.Name.Contains(keywords));
                }
                //2.按照状态筛选
                switch (status)
                {
                case "All":
                    break;

                case "1":
                    qs = qs.Where(x => x.Status == "正在审核中");
                    break;

                case "2":
                    qs = qs.Where(x => x.Status == "审核未通过");
                    break;

                case "3":
                    qs = qs.Where(x => x.Status == "等待受助中");
                    break;

                case "4":
                    qs = qs.Where(x => x.Status == "已接受受助");
                    break;

                case "5":
                    qs = qs.Where(x => x.Status == "受助已成功");
                    break;
                }
                //3.分页
                int totalThings = qs.Count();                                             //总共条目数目
                ViewBag.totalPages = (int)Math.Ceiling(totalThings / (double)numPerPage); //总共页数
                int start = (currentPage - 1) * numPerPage;                               //开始的条目
                qs = qs.OrderByDescending(x => x.ReleaseTime).Skip(start).Take(numPerPage);
                ViewBag.searchString = keywords;
                ViewBag.Status       = status;
                ViewBag.currentPage  = currentPage;
                //给视图模型赋值
                foreach (var q in qs)
                {
                    //新建一个视图模型并赋值
                    var tmp = new QuestsListViewModel();
                    tmp.Quest = q;
                    //添加到列表中
                    res.Add(tmp);
                }
            }
            return(View(res));
        }