Пример #1
0
        public IHttpActionResult Match(matchdto dto)
        {
            MatchResult rlt      = new MatchResult();
            var         csm      = _context.Consumers.Single(c => c.Openid == dto.openid);
            var         otherCsm = _context.Consumers.SingleOrDefault(c => c.Dadacode == dto.dadacode);

            if (otherCsm == null)
            {
                rlt.Code = 400;
                rlt.Msg  = "拼搭失败 - 拼搭码未找到";
                return(Ok(rlt));
            }

            if (otherCsm.Openid.Equals(dto.openid, StringComparison.OrdinalIgnoreCase))
            {
                rlt.Code = 402;
                rlt.Msg  = "拼搭失败 - 不能拼搭自己";
                return(Ok(rlt));
            }

            //fix: 两人不能交叉拼搭
            var invition = _context.Invitions
                           .FirstOrDefault(c =>
                                           (c.ConsumerOpenid == dto.openid && c.InvOpenid == otherCsm.Openid) ||
                                           (c.ConsumerOpenid == otherCsm.Openid && c.InvOpenid == dto.openid));

            if (invition != null)
            {
                rlt.Code = 401;
                rlt.Msg  = "重复拼搭";
                return(Ok(rlt));
            }
            Random rnd = new Random();

            invition = new Invition()
            {
                ConsumerOpenid = dto.openid,
                InvOpenid      = otherCsm.Openid,
                Iftmall        = true,
                MatchType      = rnd.Next(0, 6)
            };
            _context.Invitions.Add(invition);
            _context.SaveChanges();
            rlt.Code      = 200;
            rlt.Msg       = "拼搭成功";
            rlt.MatchType = invition.MatchType;
            return(Ok(rlt));
        }
Пример #2
0
        public IHttpActionResult MatchList(matchdto dto)
        {
            var list = _context.Invitions.Include(c => c.Consumer).Include(c => c.Inv)
                       .Where(c => c.ConsumerOpenid == dto.openid || c.InvOpenid == dto.openid).OrderByDescending(c => c.Id)
                       .Select(c => new UserInfoSimple
            {
                Nickname     = (c.ConsumerOpenid == dto.openid) ? c.Inv.NickName : c.Consumer.NickName,
                HeadImgUrl   = (c.ConsumerOpenid == dto.openid) ? c.Inv.HeadImgUrl : c.Consumer.HeadImgUrl,
                InvitionType = (c.ConsumerOpenid == dto.openid) ? "host" : "client",
                Invdate      = c.Invdate,
                MatchType    = c.MatchType
            }
                               ).Take(50).ToList();

            var rlt = new MatchlistResult();

            rlt.Code = 200;
            rlt.Msg  = "";
            rlt.List = list;

            return(Ok(rlt));
        }