Example #1
0
        public ActionResult DetailsReceiveThings(int?id, string action)
        {
            switch (action)
            {
            case "评价物品":
                ThingsQuests tq = db.ThingsQuests.Where(x => x.QuestId == id).FirstOrDefault();
                Things       t  = db.Things.Where(x => x.ThingId == tq.ThingId).FirstOrDefault();
                return(RedirectToAction("UploadComment", new { id = t.ThingId }));

            case "删除":
                Quests q = db.Quests.Where(x => x.QuestId == id).FirstOrDefault();
                db.Quests.Remove(q);

                Checks c = db.Checks.Where(x => x.CheckId == q.ReceiverId).FirstOrDefault();
                if (c != null)
                {
                    db.Checks.Remove(c);
                }
                Assess a = db.Assess.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();
                a.CreditPoint    -= 2;
                a.CreditLevel     = CreditsCal.getLevel(a.CreditPoint.Value);
                db.Entry(a).State = EntityState.Modified;
                db.SaveChanges();
                break;

            case "返回到列表":
                return(RedirectToAction("SelectReceiveThings"));
            }

            return(RedirectToAction("SelectReceiveThings"));
        }
        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 #3
0
        // GET: SSReceive/DetailsReceiveThings/id 受助请求详细信息页(查看信息) id=RTID
        public ActionResult DetailsReceiveThings(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Quests q  = db.Quests.Where(x => x.QuestId == id).FirstOrDefault();
            Users  qu = db.Users.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();

            ViewBag.qUserName = qu.Username;
            ViewBag.qUserId   = qu.UserId;
            if (q.Status == "审核未通过")
            {
                Checks check = db.Checks.Where(x => x.CheckId == q.CheckId).FirstOrDefault();
                ViewBag.RefuseReason = check.RefuseReason;
            }
            if (q.Status == "已接受受助")
            {
                return(RedirectToAction("CompleteReceiveThings", new { id }));
            }
            else if (q.Status == "受助已成功")
            {
                ThingsQuests tq = db.ThingsQuests.Where(x => x.QuestId == q.QuestId).FirstOrDefault();
                Things       t  = db.Things.Where(x => x.ThingId == tq.ThingId).FirstOrDefault();
                ViewBag.tId     = t.ThingId;
                ViewBag.tName   = t.Name;
                ViewBag.tType   = t.Type;
                ViewBag.tReason = t.Reason;
                ViewBag.tPhoto  = t.PhotoURL;
                ViewBag.tTime   = t.ReleaseTime;

                Users tu = db.Users.Where(x => x.UserId == t.GiverId).FirstOrDefault();
                ViewBag.tUserName = tu.Username;
                ViewBag.tUserId   = tu.UserId;

                Comments c = db.Comments.Where(x => x.ThingId == t.ThingId).FirstOrDefault();
                if (c != null)
                {
                    ViewBag.cReceiverId = c.ReceiverId;
                    ViewBag.cNew        = c.NewScore;
                    ViewBag.cSimilar    = c.SimilarScore;
                    ViewBag.cUseful     = c.UsefulScore;
                    ViewBag.cSpeed      = c.SpeedScore;
                    ViewBag.cBeautiful  = c.BeautifulScore;
                    ViewBag.cText       = c.Text;
                    ViewBag.cTime       = c.CommentTime;
                }
            }
            return(View(q));
        }
        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 }));
        }
        public ActionResult UploadGivenThings(SSUploadGivenThingsViewModel model, int?id)
        {
            int usrId = (int)HttpContext.Session["usrId"];

            if (ModelState.IsValid)
            {
                Things t = new Things();
                t.GiverId = usrId;
                //t.CheckId=NULL;
                t.Name        = model.Name;
                t.Reason      = model.Reason;
                t.Type        = model.Type;
                t.Status      = id == null ? "正在审核中" : "已接受捐赠";
                t.ReleaseTime = DateTime.Now;
                foreach (var file in model.Image)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        t.PhotoURL = Save(file, "ThingsImages");
                    }
                }
                int tId = 0;
                using (Entities db = new Entities())
                {
                    db.Things.Add(t);
                    db.SaveChanges();
                    tId = t.ThingId;
                }
                if (id != null)
                {
                    Quests q = db.Quests.Where(x => x.QuestId == (int)id).FirstOrDefault();
                    q.Status          = "已接受受助";
                    db.Entry(q).State = EntityState.Modified;

                    ThingsQuests qg = new ThingsQuests();
                    qg.QuestId = (int)id;
                    qg.ThingId = tId;
                    qg.Time    = DateTime.Now;
                    db.ThingsQuests.Add(qg);
                    db.SaveChanges();
                    return(RedirectToAction("DetailsGivenThings", new { id = tId }));
                }
                return(RedirectToAction("SelectGivenThings", "SSGiven"));
            }
            return(View(model));
        }
Example #6
0
        public ActionResult UploadReceiveThings(SSUploadReceiveThingsViewModel model, int?id)
        {
            int usrId = (int)HttpContext.Session["usrId"];

            if (ModelState.IsValid)
            {
                Quests q = new Quests();
                q.ReceiverId = usrId;
                //q.CheckId=NULL;
                q.Name        = model.Name;
                q.Reason      = model.Reason;
                q.Type        = model.Type;
                q.ReleaseTime = DateTime.Now;
                q.Status      = id == null ? "正在审核中" : "已接受受助";

                int qId = 0;
                using (Entities db = new Entities())
                {
                    db.Quests.Add(q);
                    db.SaveChanges();
                    qId = q.QuestId;
                }
                if (id != null)
                {
                    Things t = db.Things.Where(x => x.ThingId == (int)id).FirstOrDefault();
                    t.Status          = "已接受捐赠";
                    db.Entry(t).State = EntityState.Modified;

                    ThingsQuests tq = new ThingsQuests();
                    tq.QuestId = qId;
                    tq.ThingId = (int)id;
                    tq.Time    = DateTime.Now;
                    db.ThingsQuests.Add(tq);
                    db.SaveChanges();
                    return(RedirectToAction("CompleteReceiveThings", new { id = qId }));
                }
                return(RedirectToAction("SelectReceiveThings", "SSReceive"));
            }
            return(View(model));
        }
Example #7
0
        public ActionResult CompleteReceiveThings(int?id, string action)
        {
            switch (action)
            {
            case "确认送达":
                break;

            case "返回到列表":
                return(RedirectToAction("SelectReceiveThings"));
            }
            Quests q = db.Quests.Where(x => x.QuestId == id).FirstOrDefault();

            q.Status          = "受助已成功";
            db.Entry(q).State = EntityState.Modified;

            ThingsQuests tq = db.ThingsQuests.Where(x => x.QuestId == q.QuestId).FirstOrDefault();
            Things       t  = db.Things.Where(x => x.ThingId == tq.ThingId).FirstOrDefault();

            t.Status          = "捐赠已成功";
            db.Entry(t).State = EntityState.Modified;

            Assess aq = db.Assess.Where(x => x.UserId == q.ReceiverId).FirstOrDefault();

            aq.ReceiveNum++;
            aq.CreditPoint += 1;
            aq.CreditLevel  = CreditsCal.getLevel(aq.CreditPoint.Value);
            Assess ag = db.Assess.Where(x => x.UserId == t.GiverId).FirstOrDefault();

            ag.GiveNum++;
            ag.CreditPoint    += 5;
            ag.CreditLevel     = CreditsCal.getLevel(ag.CreditPoint.Value);
            db.Entry(aq).State = EntityState.Modified;
            db.Entry(ag).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("UploadComment", new { id = t.ThingId }));
        }
Example #8
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 }));
        }