Beispiel #1
0
        /// <summary>
        /// 选择收货信息
        /// </summary>
        /// <returns></returns>
        public ActionResult ChooseDeliveryAddress(string DLogUID = "", string CurrentRole = "")
        {
            if (!string.IsNullOrEmpty(DLogUID) && !string.IsNullOrEmpty(CurrentRole))
            {
                //获取当前用户ID
                string CurrentID = CurrentUser.Id;

                //获取当前用户的收货地址
                using (var db2 = new LogDealDataContext())
                {
                    //获取当前交易订单
                    var logdeal = db2.LogDeal.Where(l => l.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();
                    if (logdeal != null)
                    {
                        MyDeliveryAddress myDeliveryAddress = new MyDeliveryAddress
                        {
                            CurrentLogDeal     = logdeal,
                            CurrentRole        = CurrentRole,
                            NewdeliveryAddress = new DeliveryAddress()
                        };

                        //返回视图模型
                        return(View(myDeliveryAddress));
                    }
                }
            }
            return(View("Error"));
        }
Beispiel #2
0
        public JsonResult CancelDeal(string DealLogUID = "")
        {
            string result = "Fail";

            if (!string.IsNullOrEmpty(DealLogUID))
            {
                using (var db = new LogDealDataContext())
                {
                    //更改订单状态
                    var log = db.LogDeal.Where(d => d.DLogUID == Guid.Parse(DealLogUID)).FirstOrDefault();
                    if (log != null)
                    {
                        log.DealStatus  = "交易取消";
                        log.DealEndTime = DateTime.Now;
                        db.SubmitChanges();

                        //删除物品中的订单号
                        var treaS = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureSponsorID)).FirstOrDefault();
                        treaS.DLogUID = null;
                        repository.SaveTreasure(treaS);
                        result = "OK";
                    }
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult RecipientDealLog()
        {
            //新建视图模型List
            List <InitiateDealLog> model = new List <InitiateDealLog>();
            //获取当前登录用户ID
            string userid = CurrentUser.Id;

            //获取当前登录用户接受到交易申请的记录集合
            using (var db = new LogDealDataContext())
            {
                var deals = db.LogDeal.Where(d => ((d.TraderRecipientID == userid) && (d.DealStatus.Contains("待确认"))));
                foreach (var deal in deals)
                {
                    //收到交易的物品
                    var DealInTrea = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(deal.TreasureSponsorID)).FirstOrDefault();
                    //当前用户的物品
                    var DealOutTrea = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(deal.TreasureRecipientID)).FirstOrDefault();
                    //交易对方信息
                    var Dealer = UserManager.FindById(DealInTrea.HolderID);
                    //添加到视图模型中
                    model.Add(new InitiateDealLog
                    {
                        Dealer            = Dealer,
                        InitiateTreasures = DealInTrea,
                        MyTreasure        = DealOutTrea,
                        LogDeal           = deal
                    });
                }
            }
            return(View(model.AsEnumerable()));
        }
Beispiel #4
0
        public ActionResult MakeDeal(string TreasureSponsorID, string TreasureRecipientID)
        {
            //参数为空,报错
            if (string.IsNullOrEmpty(TreasureSponsorID) || string.IsNullOrEmpty(TreasureRecipientID))
            {
                return(View("Error", "出错"));
            }

            //首先要先验证该订单是不是出现过
            using (var db = new LogDealDataContext())
            {
                //获取与当前交易相同的记录
                var deallogs = db.LogDeal.Where(d => d.TreasureSponsorID == TreasureSponsorID && d.TreasureRecipientID == TreasureRecipientID);
                //遍历记录
                foreach (var dlog in deallogs)
                {
                    //当记录中出现以下哞种情况(即订单未完成),说明当前交易订单还在处理,这不允许创建订单,返回Error页面
                    if (dlog.DealStatus == "待确认" || dlog.DealStatus == "接受" || dlog.DealStatus == "交易中")
                    {
                        return(View("Error", "订单已存在,请勿重复申请!"));
                    }
                }
            }

            //当前登录用户UID
            string CurId = CurrentUser.Id;

            //这里验证当前发起人的物品是当前用户的,并且验证接收人的物品不是当前用户的
            var treaS = repository.Treasures
                        .Where(t => t.TreasureUID == Guid.Parse(TreasureSponsorID)).FirstOrDefault();
            var treaR = repository.Treasures
                        .Where(t => t.TreasureUID == Guid.Parse(TreasureRecipientID)).FirstOrDefault();

            if (treaR != null & treaS != null)
            {
                //确保发起物品是登录用户的,接受物品不是当前用户的
                if (treaS.HolderID == CurId && treaR.HolderID != CurId)
                {
                    //发起人id-当前登录人
                    string TraderSponsorID = CurId;
                    //接收人id-从物品获取
                    string TraderRecipientID = repository.Treasures
                                               .Where(t => t.TreasureUID == Guid.Parse(TreasureRecipientID))
                                               .FirstOrDefault().HolderID;
                    DealLogCreate dealLog = new DealLogCreate();

                    #region 生成视图模型
                    dealLog.DealInTreasure  = treaR;
                    dealLog.DealOutTreasure = treaS;
                    dealLog.QQ       = (string.IsNullOrEmpty(CurrentUser.OICQ)) ? "TA没有完善该信息" : CurrentUser.OICQ;
                    dealLog.WeChat   = (string.IsNullOrEmpty(CurrentUser.WeChat)) ? "TA没有完善该信息" : CurrentUser.WeChat;
                    dealLog.Email    = CurrentUser.Email;
                    dealLog.PhoneNum = CurrentUser.PhoneNumber;
                    #endregion

                    return(View(dealLog));
                }
            }
            return(View("Error"));
        }
Beispiel #5
0
 public ActionResult EditRemarks(DealLogCreate dealLogCreate)
 {
     using (var db = new LogDealDataContext())
     {
         //修改备注信息
         var log = db.LogDeal.Where(d => d.DLogUID == Guid.Parse(dealLogCreate.DealLogID)).FirstOrDefault();
         if (log != null)
         {
             log.RemarkSToR = dealLogCreate.Remark;
         }
         db.SubmitChanges();
     }
     return(RedirectToAction("InitiateDealLog", "Account"));
 }
Beispiel #6
0
        public ActionResult MakeDeal(DealLogCreate dealLogCreate)
        {
            //验证不为空
            if (string.IsNullOrEmpty(dealLogCreate.DealInTreasure.TreasureUID.ToString()) || string.IsNullOrEmpty(dealLogCreate.DealOutTreasure.TreasureUID.ToString()))
            {
                return(View("Error"));
            }
            else
            {
                Guid guid = Guid.NewGuid();
                //插入数据库
                using (var db = new LogDealDataContext())
                {
                    LogDeal logDeal = new LogDeal
                    {
                        DealBeginTime = DateTime.Now,
                        DealStatus    = "待确认",
                        DLogUID       = guid,
                        //备注-发起人对接收人
                        RemarkSToR = dealLogCreate.Remark,
                        //交易接收人ID
                        TraderRecipientID = dealLogCreate.DealInTreasure.HolderID,
                        //交易发起人ID
                        TraderSponsorID = dealLogCreate.DealOutTreasure.HolderID,
                        //交易给出物品ID
                        TreasureSponsorID = dealLogCreate.DealOutTreasure.TreasureUID.ToString(),
                        //交易接受物品ID
                        TreasureRecipientID = dealLogCreate.DealInTreasure.TreasureUID.ToString()
                    };
                    try
                    {
                        db.LogDeal.InsertOnSubmit(logDeal);
                        //保存操作
                        db.SubmitChanges();

                        //更新当前物品交易记录
                        var treasure = repository.Treasures.Where(t => t.TreasureUID == dealLogCreate.DealOutTreasure.TreasureUID).FirstOrDefault();
                        treasure.DLogUID = guid.ToString();
                        repository.SaveTreasure(treasure);
                    }
                    catch (Exception ex)
                    {
                        return(View("Error", ex.Message));
                    }
                }
                return(RedirectToAction("InitiateDealLog", "Account"));
            }
        }
Beispiel #7
0
        /// <summary>
        /// 拒绝申请-我收到的交易申请
        /// </summary>
        /// <returns></returns>
        public ActionResult DisagreeDeal(string DLogUID = "")
        {
            if (string.IsNullOrEmpty(DLogUID))
            {
                return(View("Error"));
            }
            //获取当前交易信息
            using (var db = new LogDealDataContext())
            {
                var deal = db.LogDeal.Where(d => d.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();

                //换入物品-对于接收人来说,换入物品是本次申请的发起人物品
                var treaR = repository.Treasures
                            .Where(t => t.TreasureUID == Guid.Parse(deal.TreasureSponsorID))
                            .FirstOrDefault();
                //换出物品-对于接收人来说,换出物品是本次申请的接收人物品
                var treaS = repository.Treasures
                            .Where(t => t.TreasureUID == Guid.Parse(deal.TreasureRecipientID))
                            .FirstOrDefault();

                //相似推荐
                //获取相似物品
                var Moretreas = repository.Treasures
                                .Where(t => t.TreasureType == treaR.TreasureType).OrderBy(t => t.Favorite).Take(3);

                //过滤是当前用户的
                Moretreas.Where(t => t.HolderID != CurrentUser.Id);

                //根据七天的收藏量
                using (var db2 = new FavoriteDataContext())
                {
                    var FavoriteTrea = db2.Favorite.Where(f => (SqlMethods.DateDiffDay(f.FavoriteTime, DateTime.Now) <= 7)).Select(f => f.TreasureID);
                    if (treaR != null && treaS != null)
                    {
                        return(View(new DealLogCreate
                        {
                            DealInTreasure = treaR,
                            DealOutTreasure = treaS,
                            Remark = deal.RemarkSToR,
                            DealLogID = DLogUID,
                            MoreTreasures = Moretreas.AsEnumerable()
                        }));
                    }
                }
            }
            return(View("Error"));
        }
Beispiel #8
0
        public ActionResult AllDealLog()
        {
            //获取当前用户ID
            string currID = CurrentUser.Id;
            //新建List
            List <LogDealTableInfo> logDealTableInfos = new List <LogDealTableInfo>();

            //获取当前登录用户的交易记录
            using (var db = new LogDealDataContext())
            {
                //获取有当前登录用户参与的交易信息
                var deals = db.LogDeal.Where(d => ((d.TraderSponsorID == currID) || (d.TraderRecipientID == currID))).ToList().AsEnumerable();

                //遍历所有交易信息
                foreach (var deal in deals)
                {
                    //获取对方用户对象
                    var TradeID = deal.TraderRecipientID == currID ? deal.TraderSponsorID : deal.TraderRecipientID;
                    var Trader  = UserManager.FindById(TradeID);

                    //添加交易记录
                    logDealTableInfos.Add(new LogDealTableInfo
                    {
                        //交易信息
                        LogDeal = deal,
                        //对方用户对象
                        Trader = new BasicUserInfo
                        {
                            UserID   = Trader.Id,
                            UserName = Trader.UserName,
                            RealName = Trader.RealName
                        },
                        //换入物品-即对方的物品
                        DealInTrea = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(deal.TraderRecipientID == currID ? deal.TreasureSponsorID : deal.TreasureRecipientID)).FirstOrDefault(),
                        //换出物品-即我的物品
                        DealOutTrea = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(deal.TraderRecipientID == currID ? deal.TreasureRecipientID : deal.TreasureSponsorID)).FirstOrDefault(),
                        IsSponsor   = deal.TraderSponsorID == currID
                    });
                }
                return(View(new UserDeal
                {
                    LogDealTableInfos = logDealTableInfos.AsEnumerable()
                }));
            }
        }
Beispiel #9
0
        /// <summary>
        /// 接受申请
        /// </summary>
        /// <returns></returns>
        public ActionResult AgreeDeal(string DLogUID = "")
        {
            //首先改变订单状态
            using (var db = new LogDealDataContext())
            {
                var log = db.LogDeal.Where(d => d.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();
                if (log != null)
                {
                    log.DealStatus = "交易中";
                    db.SubmitChanges();

                    //接受申请后,两个物品需要加入订单号
                    var treasureR = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureRecipientID)).FirstOrDefault();
                    var treasureS = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureSponsorID)).FirstOrDefault();
                    if (treasureR != null)
                    {
                        treasureR.DLogUID = log.DLogUID.ToString();
                        repository.SaveTreasure(treasureR);
                    }
                    if (treasureS != null)
                    {
                        treasureS.DLogUID = log.DLogUID.ToString();
                        repository.SaveTreasure(treasureS);
                    }
                }
            }
            //使其他包含这两样物品的交易申请失效


            //在物流信息中添加一项
            using (var db = new trackingDataContext())
            {
                //当前订单号不存在时
                if (db.Tracking.Where(t => t.DLogUID == DLogUID).FirstOrDefault() == null)
                {
                    db.Tracking.InsertOnSubmit(new Tracking
                    {
                        DLogUID = DLogUID
                    });
                    db.SubmitChanges();
                }
            }

            return(RedirectToAction("DealingLog", "Account"));
        }
Beispiel #10
0
        /// <summary>
        /// 评价-确认收货
        /// </summary>
        /// <param name="DLogUID"></param>
        /// <returns></returns>
        public ActionResult Signing(string DLogUID = "")
        {
            //获取当前用户的uid
            string userId = CurrentUser.Id;

            //获取本次交易订单对象
            if (!string.IsNullOrEmpty(DLogUID))
            {
                using (var db = new LogDealDataContext())
                {
                    var log = db.LogDeal.Where(l => l.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();

                    if (log != null)
                    {
                        //获取对方在本次交易中的对象
                        AppUser SideUser = UserManager.FindById(log.TraderSponsorID == userId ? log.TraderRecipientID : log.TraderSponsorID);
                        //获取对方在本次交易中的物品对象
                        Treasure treasure = repository.Treasures
                                            .Where(t => t.TreasureUID == Guid.Parse(log.TraderSponsorID == userId ? log.TreasureRecipientID : log.TreasureSponsorID))
                                            .FirstOrDefault();
                        if (SideUser != null && treasure != null)
                        {
                            return(View(new Score
                            {
                                CurTreasure = treasure,
                                LogDeal = log,
                                SideUser = new BasicUserInfo
                                {
                                    RealName = SideUser.RealName,
                                    UserID = SideUser.Id,
                                    UserName = SideUser.UserName,
                                    HeadImg = SideUser.HeadPortrait
                                },
                                NowEvaluation = new NowEvaluation {
                                    IsRecommend = true
                                },
                            }));
                        }
                    }
                }
            }

            return(View("Error"));
        }
Beispiel #11
0
        public ActionResult Delete(Guid treasureUID)
        {
            var trea = repository.Treasures.Where(t => t.TreasureUID == treasureUID).FirstOrDefault();

            //首先要判断该物品有否有正在进行的交易
            using (var db = new LogDealDataContext())
            {
                var logs = db.LogDeal.Where(l => l.TreasureSponsorID == treasureUID.ToString() || l.TreasureRecipientID == treasureUID.ToString());
                //如果有正在交易的记录,不能删除物品等待交易完成
                foreach (var log in logs)
                {
                    if (log.DealStatus.Contains("交易中"))
                    {
                        TempData["error"] = string.Format("{0} 有正在进行的交易,目前无法下架", trea.TreasureName);
                        return(RedirectToAction("AllTreasure"));
                    }
                    else if (log.DealStatus.Contains("待确认"))
                    {
                        log.DealStatus  = "交易取消";
                        log.DealEndTime = DateTime.Now;
                        db.SubmitChanges();
                    }
                }
            }

            //根据GUID获取对象
            Treasure deletedTreasure = repository.DeleteTreasure(treasureUID);

            //发送信息
            new Identity().AddNotice(trea.HolderID, CurrentUser.Id, "警告", string.Format("{0}有违规信息,已被管理员强制下架。", trea.TreasureName), treasureUID.ToString());

            //对象不为空
            if (deletedTreasure != null)
            {
                TempData["message"] = string.Format("{0} 已经强制下架", deletedTreasure.TreasureName);
            }

            //重定向到AllTreasure
            return(RedirectToAction("AllTreasure"));
        }
Beispiel #12
0
        public ActionResult DisagreeDeal(DealLogCreate dealLogCreate)
        {
            //更新物品信息
            //发起人的物品-因为发起人的物品在发起申请时就会记录订单号,所以拒绝后清空订单号,以便可以进行其他交易
            //接收人的物品-接收人在接受申请时,物品不会被记录订单号,即原来就可以自由交易,只有在接受交易或者自己发起交易后才会记录订单号
            var treaS = repository.Treasures.Where(t => t.TreasureUID == dealLogCreate.DealInTreasure.TreasureUID).FirstOrDefault();

            treaS.DLogUID = null;
            repository.SaveTreasure(treaS);

            //更新本次订单的记录
            using (var db = new LogDealDataContext())
            {
                var log = db.LogDeal.Where(d => d.DLogUID == Guid.Parse(dealLogCreate.DealLogID)).FirstOrDefault();
                log.RemarkRToS  = dealLogCreate.Remark;
                log.DealStatus  = "拒绝";
                log.DealEndTime = DateTime.Now;
                db.SubmitChanges();
            }

            return(RedirectToAction("AllDealLog", "Account"));
        }
Beispiel #13
0
        /// <summary>
        /// 设置收货地址
        /// </summary>
        /// <returns></returns>
        public JsonResult SetDeliveryAddress()
        {
            //获取信息
            string role               = Request["CurrentRole"];
            string LogDealUID         = Request["DLogUID"];
            string DeliveryAddressUID = Request["DeliveryAddressUID"];

            //初始化结果
            string result = "Error";

            if (!string.IsNullOrEmpty(role) && !string.IsNullOrEmpty(LogDealUID) && !string.IsNullOrEmpty(DeliveryAddressUID))
            {
                //添加收货信息
                using (var db = new LogDealDataContext())
                {
                    var log = db.LogDeal.Where(l => l.DLogUID == Guid.Parse(LogDealUID)).FirstOrDefault();
                    if (log != null)
                    {
                        //当前登录用户是接收人
                        if (role == "Recipient")
                        {
                            log.DeliveryAddressRecipientID = DeliveryAddressUID;
                            db.SubmitChanges();
                            result = "OK";
                        }
                        //当前登录用户是发起人
                        else if (role == "Sponsor")
                        {
                            log.DeliveryAddressSponsorID = DeliveryAddressUID;
                            db.SubmitChanges();
                            result = "OK";
                        }
                    }
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #14
0
        public ActionResult EditRemarks(string DLogUID = "")
        {
            if (string.IsNullOrEmpty(DLogUID))
            {
                return(View("Error"));
            }
            //获取当前交易信息
            LogDeal deal = new LogDeal();

            using (var db = new LogDealDataContext())
            {
                deal = db.LogDeal.Where(d => d.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();
            }

            //换入物品
            var treaR = repository.Treasures
                        .Where(t => t.TreasureUID == Guid.Parse(deal.TreasureRecipientID))
                        .FirstOrDefault();
            //换出物品
            var treaS = repository.Treasures
                        .Where(t => t.TreasureUID == Guid.Parse(deal.TreasureSponsorID))
                        .FirstOrDefault();

            if (treaR != null && treaS != null)
            {
                return(View(new DealLogCreate
                {
                    DealInTreasure = treaR,
                    DealOutTreasure = treaS,
                    Remark = deal.RemarkSToR,
                    DealLogID = DLogUID
                }));
            }

            return(View("Error"));
        }
Beispiel #15
0
        /// <summary>
        /// 结束的交易
        /// </summary>
        /// <returns></returns>
        public ActionResult CompleteDealLog()
        {
            //新建视图模型List
            List <CompleteDeal> model = new List <CompleteDeal>();
            //获取当前登录用户ID
            string userid = CurrentUser.Id;

            //获取当前登录用结束的交易
            using (var db = new LogDealDataContext())
            {
                var deals = db.LogDeal.Where(l => ((l.TraderRecipientID == userid) || (l.TraderSponsorID == userid)) && l.DealStatus.Contains("交易成功"));
                foreach (var deal in deals)
                {
                    //发起方物品
                    var TreaS = repository.Treasures
                                .Where(t => t.TreasureUID == Guid.Parse(deal.TreasureSponsorID))
                                .FirstOrDefault();
                    //发起人
                    var UserS = UserManager.FindById(TreaS.HolderID);

                    //接受方物品
                    var TreaR = repository.Treasures
                                .Where(t => t.TreasureUID == Guid.Parse(deal.TreasureRecipientID))
                                .FirstOrDefault();
                    //接收人
                    var UserR = UserManager.FindById(TreaR.HolderID);
                    using (var db2 = new EvaluationDataContext())
                    {
                        var Eva = db2.Evaluation.Where(e => e.DLogUID == deal.DLogUID.ToString()).FirstOrDefault();

                        //添加对象
                        model.Add(new CompleteDeal
                        {
                            UserS = new BasicUserInfo
                            {
                                UserID   = UserS.Id,
                                RealName = UserS.RealName,
                                HeadImg  = UserS.HeadPortrait,
                                Sign     = UserS.Signature,
                                BirthDay = UserS.BirthDay.ToString("yyyy-MM-dd"),
                                UserName = UserS.UserName
                            },
                            UserR = new BasicUserInfo
                            {
                                UserID   = UserR.Id,
                                RealName = UserR.RealName,
                                HeadImg  = UserR.HeadPortrait,
                                Sign     = UserR.Signature,
                                BirthDay = UserR.BirthDay.ToString("yyyy-MM-dd"),
                                UserName = UserR.UserName
                            },
                            TreasureS  = TreaS,
                            TreasureR  = TreaR,
                            Evaluation = Eva,
                            LogDeal    = deal
                        });
                    }
                }
            }

            return(View(model.AsEnumerable()));
        }
Beispiel #16
0
        public ActionResult TreasureInfo(string TreasureUID = "")
        {
            //获取当前用户id
            string id = CurrentUser.Id;

            if (!string.IsNullOrEmpty(TreasureUID))
            {
                Guid Treasureguid = Guid.Parse(TreasureUID);

                #region 增加一次浏览量
                //判断当前用户,当前物品的浏览记录是否已经存在
                using (var db = new LogDataContext())
                {
                    var logbrowse = db.LogBrowse.Where(b => (b.TreasureID == TreasureUID && b.BrowserID == id)).FirstOrDefault();

                    //不存在记录,则增加一条
                    if (logbrowse == null)
                    {
                        db.LogBrowse.InsertOnSubmit(new LogBrowse
                        {
                            BLogUID     = Guid.NewGuid(),
                            BrowserID   = id,
                            TreasureID  = TreasureUID,
                            BrowserTime = DateTime.Now
                        });
                        //物品浏览量加一
                        var trea = repository.Treasures.Where(t => t.TreasureUID == Treasureguid).FirstOrDefault();
                        trea.BrowseNum++;
                        repository.SaveTreasure(trea);
                    }
                    //若存在则修改访问时间
                    else
                    {
                        logbrowse.BrowserTime = DateTime.Now;
                    }
                    db.SubmitChanges();
                }
                #endregion

                Treasure treasure = repository.Treasures.Where(t => t.TreasureUID == Treasureguid).FirstOrDefault();
                var      imgs     = treasure.DetailPic.Split('|');
                if (treasure != null)
                {
                    //判断是否已经收藏
                    bool isFavarite = false;
                    using (var db = new FavoriteDataContext())
                    {
                        var fav = db.Favorite.Where(f => (f.UserID == id && f.TreasureID == TreasureUID)).FirstOrDefault();
                        //若不为空,即存在记录,则说明已经收藏
                        if (fav != null)
                        {
                            isFavarite = true;
                        }
                    }

                    //获取浏览记录
                    List <BrowseLog> browses = new List <BrowseLog>();
                    using (var db = new LogDataContext())
                    {
                        var logBrowses = db.LogBrowse.Where(b => b.TreasureID == TreasureUID).OrderByDescending(b => b.BrowserTime).Take(6);
                        foreach (var log in logBrowses)
                        {
                            var user = UserManager.FindById(log.BrowserID);
                            if (user != null)
                            {
                                browses.Add(new BrowseLog
                                {
                                    Browser = new BasicUserInfo
                                    {
                                        HeadImg  = user.HeadPortrait,
                                        UserID   = user.Id,
                                        Gender   = user.Gender,
                                        UserName = user.UserName
                                    },
                                    BrowserTime = log.BrowserTime
                                });
                            }
                        }
                    }


                    //生成推荐信息
                    int DisRecommend = 0;
                    int Recommend    = 0;
                    // 1.首先找出当前用户完成的订单
                    using (var db = new LogDealDataContext())
                    {
                        var logs = db.LogDeal.Where(l => ((l.TraderRecipientID == id || l.TraderSponsorID == id) && (l.DealStatus == "交易成功")));
                        using (var db2 = new EvaluationDataContext())
                        {
                            //遍历所有完成的订单
                            foreach (var log in logs)
                            {
                                var eva = db2.Evaluation.Where(e => e.DLogUID == log.DLogUID.ToString()).FirstOrDefault();
                                //本次交易用户是接收人,则需要发起人的评价
                                if (log.TraderRecipientID == id)
                                {
                                    //推荐
                                    if (eva.IsRecommendSToR == true)
                                    {
                                        Recommend++;
                                    }
                                    else if (eva.IsRecommendSToR == false)
                                    {
                                        DisRecommend++;
                                    }
                                }
                                else
                                {
                                    if (eva.IsRecommendRToS == true)
                                    {
                                        Recommend++;
                                    }
                                    else if (eva.IsRecommendRToS == false)
                                    {
                                        DisRecommend++;
                                    }
                                }
                            }
                        }
                    }


                    //定义一个视图模型
                    TreaInfo treaInfo = new TreaInfo
                    {
                        HolderInfo    = GetLoginUserInfo(treasure.HolderID),
                        LoginUserInfo = CurrentUser,
                        treasureInfo  = treasure,
                        //108是生成图片路径的固定的长度
                        DetailImgs = imgs.Where(t => t.Length == 108),
                        IsFavorite = isFavarite,
                        CurrenUser = new BasicUserInfo
                        {
                            HeadImg = CurrentUser.HeadPortrait
                        },
                        browseLogs   = browses.AsEnumerable(),
                        DisRecommend = DisRecommend,
                        Recommend    = Recommend
                    };
                    return(View(treaInfo));
                }
            }
            return(View("List"));
        }
Beispiel #17
0
        public ActionResult Index()
        {
            //新建视图
            IndexViewModel model = new IndexViewModel();

            var Alltreasure = repository.Treasures.Where(t => t.DLogUID == null).ToList().AsEnumerable();

            #region 随便看看
            //判断数量,决定要显示的物品数量
            int cnt = Alltreasure.Count() < 50 ? 4 : Alltreasure.Count() / 10;
            cnt = cnt > Alltreasure.Count() ? Alltreasure.Count() : cnt;
            List <Treasure> treasureRandom = new List <Treasure>();
            for (int i = 0; i < cnt; i++)
            {
                var r   = new Random(Guid.NewGuid().GetHashCode());
                int res = r.Next(0, Alltreasure.Count());
                treasureRandom.Add(Alltreasure.ElementAt(res));
            }
            List <TreasureAndHolderInfo> treasuresRandomList = new List <TreasureAndHolderInfo>();
            //去掉重复元素,然后遍历
            foreach (var trea in treasureRandom.Distinct())
            {
                //获取物品所属人对象
                var holder = UserManager.FindById(trea.HolderID);

                //是否被收藏
                bool IsFavorite = false;
                using (var db = new FavoriteDataContext())
                {
                    var log = db.Favorite.Where(f => (f.TreasureID == trea.TreasureUID.ToString() && f.UserID == CurrentUser.Id)).FirstOrDefault();
                    if (log != null)
                    {
                        IsFavorite = true;
                    }
                }
                if (holder != null)
                {
                    var detail = trea.DetailPic.Split('|');
                    trea.DetailPic = detail.Last();
                    treasuresRandomList.Add(new TreasureAndHolderInfo
                    {
                        Holder     = holder,
                        Treasure   = trea,
                        IsFavorite = IsFavorite
                    });
                }
            }
            model.RandomTrea = treasuresRandomList.AsEnumerable();
            #endregion

            #region 每日推荐
            using (var db = new LogDataContext())
            {
                //获取当前用户的浏览记录
                var log = db.LogBrowse.Where(b => b.BrowserID == CurrentUser.Id).Select(b => b.TreasureID).ToList();
                //获取用户浏览过的物品类型集合
                var treas = repository.Treasures.Where(t => log.Contains(t.TreasureUID.ToString())).ToList();
                var types = treas.Select(t => t.TreasureType);
                //获取这些这些类型的浏览量
                List <TreasureTypeCnt> treasuretypecnt = new List <TreasureTypeCnt>();
                int AllCnt = 0;
                foreach (var type in types)
                {
                    int             Typecnt         = treas.Where(t => t.TreasureType == type).Count();
                    TreasureTypeCnt treasureTypeCnt = new TreasureTypeCnt {
                    };
                    treasureTypeCnt.type = type;
                    treasureTypeCnt.cnt  = Typecnt;
                    treasuretypecnt.Add(treasureTypeCnt);
                    AllCnt += Typecnt;
                }
                //排序
                treasuretypecnt.OrderBy(t => t.cnt);

                //根据排序后的类型,进行推荐相同类型的物品
                List <Treasure> trea = new List <Treasure>();
                foreach (var ty in treasuretypecnt)
                {
                    int TreaCnt = ty.cnt * 5 / AllCnt;
                    var tr      = repository.Treasures.Where(t => t.TreasureType == ty.type).Take(TreaCnt);
                    trea.AddRange(tr);
                }

                //去掉重复元素,然后遍历
                List <TreasureAndHolderInfo> RecommandTrea = new List <TreasureAndHolderInfo>();

                foreach (var Rtrea in trea.Distinct())
                {
                    //获取物品所属人对象
                    var holder = UserManager.FindById(Rtrea.HolderID);

                    //是否被收藏
                    bool IsFavorite = false;
                    using (var db2 = new FavoriteDataContext())
                    {
                        var log2 = db2.Favorite.Where(f => (f.TreasureID == Rtrea.TreasureUID.ToString() && f.UserID == CurrentUser.Id)).FirstOrDefault();
                        if (log2 != null)
                        {
                            IsFavorite = true;
                        }
                    }
                    if (holder != null)
                    {
                        var detail = Rtrea.DetailPic.Split('|');
                        Rtrea.DetailPic = detail.Last();
                        RecommandTrea.Add(new TreasureAndHolderInfo
                        {
                            Holder     = holder,
                            Treasure   = Rtrea,
                            IsFavorite = IsFavorite
                        });
                    }
                }
                model.RecommandTrea = RecommandTrea.AsEnumerable();
            }
            #endregion

            #region 最新物品
            int cnt2 = Alltreasure.Count() > 6 ? 6 : Alltreasure.Count();
            Alltreasure.OrderBy(t => t.UploadTime);
            List <Treasure> treasuresNew = Alltreasure.Take(cnt2).ToList();
            List <TreasureAndHolderInfo> treasuresNewList = new List <TreasureAndHolderInfo>();
            foreach (var trea in treasuresNew)
            {
                //获取物品所属人
                var holder = UserManager.FindById(trea.HolderID);

                //是否被收藏
                bool IsFavorite = false;
                using (var db = new FavoriteDataContext())
                {
                    //获取七天内的收藏记录
                    var FavoriteTrea = db.Favorite.Where(f => (SqlMethods.DateDiffDay(f.FavoriteTime, DateTime.Now) <= 7)).Select(f => f.TreasureID);
                    var Treas        = repository.Treasures.Where(t => FavoriteTrea.Contains(t.TreasureUID.ToString()));
                    //生成视图模型
                    List <TreasureFavoriteCnt> treafavos = new List <TreasureFavoriteCnt>();
                    foreach (var favo in FavoriteTrea.Distinct())
                    {
                        var favorecnt = Treas.Where(t => t.TreasureUID == Guid.Parse(favo)).Count();
                        treafavos.Add(new TreasureFavoriteCnt
                        {
                            cnt     = favorecnt,
                            treauid = favo
                        });
                    }
                    //排序
                    treafavos.OrderBy(t => t.cnt);

                    var log = db.Favorite.Where(f => (f.TreasureID == trea.TreasureUID.ToString() && f.UserID == CurrentUser.Id)).FirstOrDefault();
                    if (log != null)
                    {
                        IsFavorite = true;
                    }
                }
                if (holder != null)
                {
                    treasuresNewList.Add(new TreasureAndHolderInfo
                    {
                        Holder     = holder,
                        Treasure   = trea,
                        IsFavorite = IsFavorite
                    });
                }
            }
            model.NewestTrea = treasuresNewList.AsEnumerable();
            #endregion

            #region 最近热门
            var treaHot     = repository.Treasures.Where(t => t.DLogUID == null).OrderBy(t => t.BrowseNum);
            int cnt3        = treaHot.Count() > 6 ? 6 : treaHot.Count();
            var treaHotList = treaHot.Take(cnt3);
            List <TreasureAndHolderInfo> treasuresHotList = new List <TreasureAndHolderInfo>();
            foreach (var trea in treaHotList)
            {
                var  holder     = UserManager.FindById(trea.HolderID);
                bool isFavorite = false;
                using (var db = new FavoriteDataContext())
                {
                    var log = db.Favorite.Where(f => (f.TreasureID == trea.TreasureUID.ToString() && f.UserID == CurrentUser.Id)).FirstOrDefault();
                    if (log != null)
                    {
                        isFavorite = true;
                    }
                }
                if (holder != null)
                {
                    treasuresHotList.Add(new TreasureAndHolderInfo
                    {
                        Holder     = holder,
                        Treasure   = trea,
                        IsFavorite = isFavorite
                    });
                }
            }
            model.HotTrea = treasuresHotList.AsEnumerable();
            #endregion

            #region 数据
            model.TreasureCnt = repository.Treasures.Count();
            using (var db = new LogDealDataContext())
            {
                var deallog = db.LogDeal.Where(l => (l.DealStatus == "交易中" || l.DealStatus == "待确认"));
                model.DealingCnt = deallog.Count();
            }
            using (var db = new EvaluationDataContext())
            {
                var Evaluation = db.Evaluation;
                model.EvaluationCnt = Evaluation.Count();
            }
            using (var db = new AspNetUserDataContext())
            {
                var user = db.AspNetUsers;
                model.UserCnt = user.Count();
            }
            #endregion

            return(View(model));
        }
Beispiel #18
0
        /// <summary>
        /// 查看物流信息
        /// </summary>
        /// <param name="DLogUID">订单号</param>
        /// <param name="Role">查看物流的角色</param>
        /// <returns></returns>
        public ActionResult DeliveryInfo(string DLogUID = "", string Role = "")
        {
            //获取当前登录人的ID
            string userId = CurrentUser.Id;

            //当前物流单号
            string DeliveryNum = string.Empty;

            //获取订单信息
            using (var db = new LogDealDataContext())
            {
                var log = db.LogDeal.Where(l => l.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();
                if (log != null)
                {
                    using (var db2 = new trackingDataContext())
                    {
                        //获取物流对象
                        var tracking = db2.Tracking.Where(t => t.DLogUID == DLogUID).FirstOrDefault();

                        //从订单信息中获取当前用户在本次交易中的角色
                        //是接收人
                        if (log.TraderRecipientID == userId)
                        {
                            //从Role中判断,用户要查询自己的还是对方的物流信息
                            if (Role == "Ta")
                            {
                                DeliveryNum = tracking.SponsorTrackingNum ?? "";
                            }
                            else if (Role == "My")
                            {
                                DeliveryNum = tracking.RecipientTrackingNum ?? "";
                            }
                        }
                        //发起人
                        else if (log.TraderSponsorID == userId)
                        {
                            //从Role中判断,用户要查询自己的还是对方的物流信息
                            if (Role == "Ta")
                            {
                                DeliveryNum = tracking.RecipientTrackingNum ?? "";
                            }
                            else if (Role == "My")
                            {
                                DeliveryNum = tracking.SponsorTrackingNum ?? "";
                            }
                        }
                    }
                }
                else
                {
                    return(View("Error", "错误"));
                }
            }

            //查询物流信息
            if (!string.IsNullOrEmpty(DeliveryNum))
            {
                Delivery delivery = new Identity().GetDeliveryInfo(DeliveryNum);
                return(View(delivery));
            }

            return(View("Error", "错误"));
        }
Beispiel #19
0
        /// <summary>
        /// 订单详情信息
        /// </summary>
        /// <returns></returns>
        public ActionResult DealAllInfo(string DLogUID = "")
        {
            if (!string.IsNullOrEmpty(DLogUID))
            {
                //获取订单对象
                using (var db = new LogDealDataContext())
                {
                    var log = db.LogDeal.Where(l => l.DLogUID == Guid.Parse(DLogUID)).FirstOrDefault();
                    if (log != null)
                    {
                        #region 获取物品对象
                        var TreasureS = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureSponsorID)).FirstOrDefault();
                        var TreasureR = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureRecipientID)).FirstOrDefault();
                        #endregion

                        #region 获取收货信息
                        DeliveryAddress deliveryAddressS = new DeliveryAddress();
                        DeliveryAddress deliveryAddressR = new DeliveryAddress();
                        using (var db2 = new DeliveryAddressDataContext())
                        {
                            deliveryAddressS = db2.DeliveryAddress.Where(d => d.DeliveryAddressUID == log.DeliveryAddressSponsorID).FirstOrDefault();
                            deliveryAddressR = db2.DeliveryAddress.Where(d => d.DeliveryAddressUID == log.DeliveryAddressRecipientID).FirstOrDefault();
                        }
                        #endregion

                        #region 用户信息
                        BasicUserInfo basicUserInfoS = new BasicUserInfo();
                        BasicUserInfo basicUserInfoR = new BasicUserInfo();
                        var           userS          = UserManager.FindById(log.TraderSponsorID);
                        var           userR          = UserManager.FindById(log.TraderRecipientID);
                        if (userS != null && userR != null)
                        {
                            basicUserInfoS.HeadImg  = userS.HeadPortrait;
                            basicUserInfoS.RealName = userS.RealName;
                            basicUserInfoS.PhoNum   = userS.PhoneNumber;
                            basicUserInfoS.Email    = userS.Email;

                            basicUserInfoR.HeadImg  = userR.HeadPortrait;
                            basicUserInfoR.RealName = userR.RealName;
                            basicUserInfoR.PhoNum   = userR.PhoneNumber;
                            basicUserInfoR.Email    = userR.Email;
                        }
                        #endregion

                        #region 评价信息
                        Evaluation evaluation = new Evaluation();
                        using (var db3 = new EvaluationDataContext())
                        {
                            evaluation = db3.Evaluation.Where(e => e.DLogUID == log.DLogUID.ToString()).FirstOrDefault();
                        }
                        #endregion

                        //返回视图模型
                        return(View(new DealAllInfo
                        {
                            BasicUserInfoR = basicUserInfoR,
                            BasicUserInfoS = basicUserInfoS,
                            DeliveryAddressR = deliveryAddressR,
                            DeliveryAddressS = deliveryAddressS,
                            Evaluation = evaluation,
                            TreasureR = TreasureR,
                            TreasureS = TreasureS
                        }));
                    }
                }
            }
            return(View("Error"));
        }
Beispiel #20
0
        /// <summary>
        /// 正在进行的交易
        /// </summary>
        /// <returns></returns>
        public ActionResult DealingLog()
        {
            //获取当前登录人ID
            string Id = CurrentUser.Id;

            //新建List视图模型
            List <DealingLog> dealingLogs = new List <DealingLog>();

            //获取状态是“交易中”的交易集合
            using (var db = new LogDealDataContext())
            {
                var logs = db.LogDeal.Where(d => (d.DealStatus == "交易中") && ((d.TraderRecipientID == Id) || (d.TraderSponsorID == Id)));

                foreach (var log in logs)
                {
                    //获取对方个人ID
                    string TaID = log.TraderRecipientID == Id ? log.TraderSponsorID : log.TraderRecipientID;

                    //获取对方信息
                    AppUser TaInfo = UserManager.FindById(TaID);

                    //获取物品信息
                    //接受人的物品
                    var TreaR = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureRecipientID)).FirstOrDefault();
                    //发起人的物品
                    var TreaS = repository.Treasures.Where(t => t.TreasureUID == Guid.Parse(log.TreasureSponsorID)).FirstOrDefault();

                    //检查当前用户是否已经评价
                    bool IsEvaluation = false;
                    using (var db3 = new EvaluationDataContext())
                    {
                        var eva = db3.Evaluation.Where(e => e.DLogUID == log.DLogUID.ToString()).FirstOrDefault();
                        //如果当前订单的评价信息存在
                        if (eva != null)
                        {
                            //判断当前用户是否已经评价
                            if (Id == log.TraderSponsorID)
                            {
                                //当前用户时发起人
                                if (eva.IsRecommendSToR != null)
                                {
                                    IsEvaluation = true;
                                }
                            }
                            else if (Id == log.TraderRecipientID)
                            {
                                if (eva.IsRecommendRToS != null)
                                {
                                    IsEvaluation = true;
                                }
                            }
                            else
                            {
                                return(View("Error"));
                            }
                        }
                    }

                    //查看对方收货地址
                    DeliveryAddress deliveryAddress = new DeliveryAddress();
                    using (var db4 = new DeliveryAddressDataContext())
                    {
                        if (log.TraderRecipientID == TaID)
                        {
                            deliveryAddress = db4.DeliveryAddress.Where(a => a.DeliveryAddressUID == log.DeliveryAddressRecipientID).FirstOrDefault();
                        }
                        else
                        {
                            deliveryAddress = db4.DeliveryAddress.Where(a => a.DeliveryAddressUID == log.DeliveryAddressSponsorID).FirstOrDefault();
                        }
                    }

                    //添加视图模型
                    if (TreaR != null && TreaS != null)
                    {
                        using (var db2 = new trackingDataContext())
                        {
                            var tracking = db2.Tracking.Where(t => t.DLogUID == log.DLogUID.ToString()).FirstOrDefault();
                            dealingLogs.Add(new DealingLog
                            {
                                LogDeal = log,
                                My      = CurrentUser,
                                //我的物品-如果这个接受物品所属人的ID不是当前登录人ID,则当前登录人即我是发起人
                                MyTreasure = TreaR.HolderID == Id ? TreaR : TreaS,
                                Ta         = TaInfo,
                                TaTreasure = TreaR.HolderID == TaID ? TreaR : TreaS,
                                Tracking   = tracking,
                                //当前用户在本次交易中是什么角色
                                CurrentUserRole = TreaR.HolderID == Id ? "Recipient" : "Sponsor",
                                IsEvaluation    = IsEvaluation,
                                DeliveryAddress = deliveryAddress
                            });
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //返回视图
            return(View(dealingLogs.AsEnumerable()));
        }
Beispiel #21
0
        /// <summary>
        /// 用户个人信息
        /// </summary>
        /// <param name="UserID">对象用户UID</param>
        /// <returns></returns>
        public ActionResult AccountInfo(string UserID = "")
        {
            //新建视图模型
            AccountInfoViewModel model = new AccountInfoViewModel
            {
                TotalBrowseNum   = 0,
                TotalFavorite    = 0,
                TotalTreasureNum = 0
            };

            if (string.IsNullOrEmpty(UserID))
            {
                UserID = CurrentUser.Id;
            }

            if (!string.IsNullOrEmpty(UserID))
            {
                //获取查看的用户对象
                var user = UserManager.FindById(UserID);
                if (user != null)
                {
                    //添加用户对象
                    model.TargetUser = user;
                    //获取该用户的物品集合,且没有交易
                    var treasures = repository.Treasures.Where(t => t.HolderID == UserID);
                    if (treasures != null)
                    {
                        //遍历
                        foreach (var trea in treasures)
                        {
                            model.TotalBrowseNum += trea.BrowseNum;
                            model.TotalFavorite  += trea.Favorite;
                            model.TotalTreasureNum++;
                        }
                        //添加物品集合,选择前三个,按时间排序,并且没有正在的交易
                        var TargetTrea = treasures.Where(t => t.DLogUID == null).OrderBy(t => t.UploadTime).Take(3);

                        using (var db = new FavoriteDataContext())
                        {
                            //根据Treasure生成对应的TreasureCard
                            List <TreasureCard> treasureCards_T = new List <TreasureCard>();
                            foreach (var trea in TargetTrea)
                            {
                                treasureCards_T.Add(new TreasureCard
                                {
                                    Treasure = trea,
                                });
                            }
                            model.TargetTreasures = treasureCards_T.AsEnumerable();

                            //收藏
                            string FavoriteTreaID = string.Empty;
                            var    favorites      = db.Favorite.Where(f => f.UserID == UserID).OrderBy(f => f.FavoriteTime).Take(3);
                            foreach (var favo in favorites)
                            {
                                FavoriteTreaID += "|||" + favo.TreasureID;
                            }
                            //获取收藏的物品
                            var favoriteTrea = repository.Treasures.Where(t => FavoriteTreaID.Contains(t.TreasureUID.ToString()));

                            //收藏物品
                            List <TreasureCard> treasureCards_F = new List <TreasureCard>();
                            foreach (var trea in favoriteTrea)
                            {
                                //获取物品所属人
                                var holder = UserManager.FindById(trea.HolderID);

                                treasureCards_F.Add(new TreasureCard
                                {
                                    Treasure       = trea,
                                    TreasureHolder = new BasicUserInfo
                                    {
                                        UserID   = holder.Id,
                                        UserName = holder.UserName,
                                        HeadImg  = holder.HeadPortrait
                                    }
                                });
                            }

                            //添加视图
                            model.TargetFavorite = treasureCards_F.AsEnumerable();
                        }

                        //评价
                        using (var db2 = new LogDealDataContext())
                        {
                            //首先获取有当前用户的所有订单
                            var logs = db2.LogDeal.Where(l => (l.TraderRecipientID == UserID || l.TraderSponsorID == UserID));
                            List <UserEvaluation> userEvaluations = new List <UserEvaluation>();
                            //遍历所有订单,获取获取每个订单中的评价
                            foreach (var log in logs)
                            {
                                using (var db3 = new EvaluationDataContext())
                                {
                                    //获取订单中的评价信息
                                    var evaluation = db3.Evaluation.Where(e => e.DLogUID == log.DLogUID.ToString()).FirstOrDefault();
                                    //如果有评价信息
                                    if (evaluation != null)
                                    {
                                        //用户是接收人,则需要的评论是发起人
                                        if (log.TraderRecipientID == UserID)
                                        {
                                            //获取评论人对象
                                            var evaUser = UserManager.FindById(log.TraderSponsorID);

                                            //添加评价信息
                                            userEvaluations.Add(new UserEvaluation
                                            {
                                                Time           = evaluation.EvaTimeSToR,
                                                EvaluationInfo = evaluation.EvaluationSToR,
                                                Holder         = new BasicUserInfo
                                                {
                                                    HeadImg  = evaUser.HeadPortrait,
                                                    UserName = evaUser.UserName,
                                                    UserID   = evaUser.Id
                                                },
                                                IsReaommend = evaluation.IsRecommendSToR
                                            });
                                        }
                                        else if (log.TraderSponsorID == UserID)
                                        {
                                            //获取评论人对象
                                            var evaUser = UserManager.FindById(log.TraderRecipientID);

                                            //添加评价信息
                                            userEvaluations.Add(new UserEvaluation
                                            {
                                                Time           = evaluation.EvaTimeRToS,
                                                EvaluationInfo = evaluation.EvaluationRToS,
                                                Holder         = new BasicUserInfo
                                                {
                                                    HeadImg  = evaUser.HeadPortrait,
                                                    UserName = evaUser.UserName,
                                                    UserID   = evaUser.Id
                                                },
                                                IsReaommend = evaluation.IsRecommendRToS
                                            });
                                        }
                                    }
                                }
                            }
                            //添加数据
                            model.Evaluations = userEvaluations;
                            return(View(model));
                        }
                    }
                }
            }

            return(View("Error"));
        }
Beispiel #22
0
        public ActionResult Signing(Score score)
        {
            if (!string.IsNullOrEmpty(score.LogDeal.DLogUID.ToString()))
            {
                //首先判断当前用户在本次订单中的身份
                string userid = CurrentUser.Id;

                //增加评论记录
                using (var db = new EvaluationDataContext())
                {
                    using (var db2 = new LogDealDataContext())
                    {
                        //获取记录对象
                        var log = db2.LogDeal.Where(l => l.DLogUID == score.LogDeal.DLogUID).FirstOrDefault();
                        //首先判断当前订单号的记录是否已经存在
                        var eveluation = db.Evaluation.Where(e => e.DLogUID == score.LogDeal.DLogUID.ToString()).FirstOrDefault();

                        if (log != null)
                        {
                            //根据当前用户的身份插入评论记录
                            if (userid == log.TraderRecipientID)
                            {
                                //不存在,则插入新的数据
                                if (eveluation == null)
                                {
                                    db.Evaluation.InsertOnSubmit(new Evaluation
                                    {
                                        DLogUID         = score.LogDeal.DLogUID.ToString(),
                                        EvaluationRToS  = score.NowEvaluation.EvaluationInfo,
                                        EvaTimeRToS     = DateTime.Now,
                                        IsRecommendRToS = score.NowEvaluation.IsRecommend
                                    });
                                }
                                //存在,则更新
                                else
                                {
                                    eveluation.EvaluationRToS  = score.NowEvaluation.EvaluationInfo;
                                    eveluation.EvaTimeRToS     = DateTime.Now;
                                    eveluation.IsRecommendRToS = score.NowEvaluation.IsRecommend;
                                }
                            }
                            else if (userid == log.TraderSponsorID)
                            {
                                //不存在
                                if (eveluation == null)
                                {
                                    db.Evaluation.InsertOnSubmit(new Evaluation
                                    {
                                        DLogUID         = score.LogDeal.DLogUID.ToString(),
                                        EvaluationSToR  = score.NowEvaluation.EvaluationInfo,
                                        EvaTimeSToR     = DateTime.Now,
                                        IsRecommendSToR = score.NowEvaluation.IsRecommend
                                    });
                                }
                                //存在更新
                                else
                                {
                                    eveluation.EvaluationSToR  = score.NowEvaluation.EvaluationInfo;
                                    eveluation.EvaTimeSToR     = DateTime.Now;
                                    eveluation.IsRecommendSToR = score.NowEvaluation.IsRecommend;
                                }
                            }

                            //判断评价信息是否双方都完成-如果评价信息原本就存在,说明双方都评价完成了
                            if (eveluation != null)
                            {
                                log.DealEndTime = DateTime.Now;
                                log.DealStatus  = "交易成功";
                                db2.SubmitChanges();
                            }
                        }
                    }
                    //保存数据
                    db.SubmitChanges();
                    return(RedirectToAction("DealingLog", "Account"));
                }
            }
            return(View("Error", "出错"));
        }