예제 #1
0
 public string Import(int mid,string name,bool isTemp,int rid)
 {
     YogaEntities ye = new YogaEntities();
     Member cc = ye.Member.FirstOrDefault((ccc) => ccc.Id == mid);
     if (cc == null) return string.Format("编号为{0}的会员不存在", mid);
     ImportRecord ir = new ImportRecord()
     {
          Date = DateTime.Now,
           IsTemp = isTemp,
            MemberId = mid,
             MemberName = name,
     };
     ye.AddToImportRecord(ir);
     if (ye.SaveChanges() != 1) return "进场失败";
     Rack r = ye.Rack.FirstOrDefault((rr) => rr.Id == rid && (rr.RenterId==null || rr.RentExpire<=DateTime.Now));
     if (r != null)
     {
         r.RentDate = DateTime.Now;
         r.RentExpire = r.RentDate.AddHours(8);
         r.RenterId = mid;
         ye.SaveChanges();
     }
     Member m = ye.Member.FirstOrDefault((rr) => rr.Id == ir.Member.Id);
     if (m == null)
         return "没有该会员";
     if (m.IsTemp && m.TempTimes > 0)
     {
         m.TempTimes -= 1;
         cc.JoneCount += 1;
         ye.SaveChanges();
         return "进场成功";
     }
     if (m.IsTemp && m.TempTimes <= 0)
     {
         return "次数不足";
     }
     cc.JoneCount += 1;
     ye.SaveChanges();
     return "进场成功";
 }