예제 #1
0
        public Rtn <bool> next([FromBody] ResetPartnerInput input)
        {
            var partner = this.dataContext.partners.Find(input.partnerId);

            if (partner != null)
            {
                var nextPartners      = (from p in this.dataContext.partners where p.sort >= partner.sort select p).ToList();
                var nextFirsetPartner = (from p in nextPartners orderby p.sort select p).FirstOrDefault();
                if (nextFirsetPartner != null)
                {
                    Console.WriteLine("current:" + partner.sort + "  next:" + nextFirsetPartner.sort);
                    if (nextFirsetPartner.sort == partner.sort)
                    {
                        partner.sort += 1;
                        this.dataContext.SaveChanges();
                    }
                    else
                    {
                        var currentSort = partner.sort;
                        partner.sort           = nextFirsetPartner.sort;
                        nextFirsetPartner.sort = currentSort;
                        this.dataContext.SaveChanges();
                    }
                    return(Rtn <bool> .Success(true, "后置成功"));
                }
                else
                {
                    return(Rtn <bool> .Error("伙伴已置底"));
                }
            }
            else
            {
                return(Rtn <bool> .Error("伙伴不存在"));
            }
        }
예제 #2
0
        public Rtn <bool> pre([FromBody] ResetPartnerInput input)
        {
            var partner = this.dataContext.partners.Find(input.partnerId);

            if (partner != null)
            {
                var prePartners     = (from p in this.dataContext.partners where p.sort <= partner.sort select p).ToList();
                var preFirstPartner = (from p in prePartners orderby p.sort descending select p).FirstOrDefault();
                if (preFirstPartner != null)
                {
                    if (preFirstPartner.sort == partner.sort)
                    {
                        partner.sort -= 1;
                        this.dataContext.SaveChanges();
                        return(Rtn <bool> .Success(true, "前置成功"));
                    }
                    else
                    {
                        var currentSort = partner.sort;
                        partner.sort         = preFirstPartner.sort;
                        preFirstPartner.sort = currentSort;
                        this.dataContext.SaveChanges();
                        return(Rtn <bool> .Success(true, "前置成功"));
                    }
                }
                else
                {
                    return(Rtn <bool> .Error("已经顶部了"));
                }
            }
            else
            {
                return(Rtn <bool> .Error("信息不存"));
            }
        }
예제 #3
0
        public object reset2Bottom([FromBody] ResetPartnerInput input)
        {
            var partner = this.dataContext.partners.Find(input.partnerId);

            if (partner != null)
            {
                var bottomPartner = (from p in this.dataContext.partners orderby p.sort descending select p).FirstOrDefault();
                partner.sort += 1;
                this.dataContext.SaveChanges();
                return(Rtn <bool> .Success(true, "置底成功"));
            }
            else
            {
                return(Rtn <bool> .Error("重置到底部"));
            }
        }
예제 #4
0
        public object reset2Top([FromBody] ResetPartnerInput input)
        {
            var partner = this.dataContext.partners.Find(input.partnerId);

            Console.WriteLine(input.partnerId);
            if (partner != null)
            {
                var firstPartner = (from p in this.dataContext.partners orderby p.sort select p).FirstOrDefault();
                partner.sort = firstPartner.sort - 1;
                this.dataContext.SaveChanges();
                return(Rtn <bool> .Success(true, "置顶成功"));
            }
            else
            {
                return(Rtn <bool> .Success(false, "伙伴不存在"));
            }
        }