public async Task <ResponseData <List <TransactionRecord> > > RecordsAsync([FromBody] RechargeRequest request) { if (!request.IsValid()) { return(new ResponseData <List <TransactionRecord> >() { Succeed = false, Message = "用户验证失败" }); } DateTime now = DateTime.Now; var records = await db.TransactionRecords .Where(p => p.CarOwnerID == request.UserID) .OrderByDescending(p => p.Time).Take(120).ToListAsync();//仅提取最后120条数据 return(new ResponseData <List <TransactionRecord> >(records)); }
public async Task <ResponseData <TransactionRecord> > RechargeAsync([FromBody] RechargeRequest request) { if (!request.IsValid()) { return(new ResponseData <TransactionRecord>() { Succeed = false, Message = "用户验证失败" }); } //此处需要进行验证 TransactionRecord record = new TransactionRecord() { CarOwnerID = request.UserID, Time = DateTime.Now }; switch (request.Type) { case "money": { var result = await TransactionService.RechargeMoneyAsync(db, request.UserID, request.Amount); return(new ResponseData <TransactionRecord>(result)); } case "time": { var result = await TransactionService.RechargeTimeAsync(db, request.UserID, request.Months); if (result == null) { return(new ResponseData <TransactionRecord>() { Message = "充值失败,余额不足", Succeed = false }); } return(new ResponseData <TransactionRecord>(result)); } default: throw new NotImplementedException(); } }