public async Task <APIResponse> Activity([FromBody] ActivityModel model) { var sortExpression = new Dictionary <string, System.Linq.Expressions.Expression <Func <DAL.Models.UserActivity, object> > >() { { "date", _ => _.TimeCreated }, }; // validate if (BasePagerModel.IsInvalid(model, sortExpression.Keys, out var errFields)) { return(APIResponse.BadRequest(errFields)); } var user = await GetUserFromDb(); var query = ( from a in DbContext.UserActivity where a.UserId == user.Id select a ); var page = await DalExtensions.PagerAsync(query, model.Offset, model.Limit, sortExpression.GetValueOrDefault(model.Sort), model.Ascending ); var list = from i in page.Selected select new ActivityViewItem() { Type = i.Type.ToLower(), Comment = i.Comment, Ip = i.Ip, Agent = i.Agent, Date = ((DateTimeOffset)i.TimeCreated).ToUnixTimeSeconds(), } ; return(APIResponse.Success( new ActivityView() { Items = list.ToArray(), Limit = model.Limit, Offset = model.Offset, Total = page.TotalCount, } )); }
public async Task <APIResponse> FiatHistory([FromBody] FiatHistoryModel model) { var sortExpression = new Dictionary <string, System.Linq.Expressions.Expression <Func <DAL.Models.UserFinHistory, object> > >() { { "date", _ => _.TimeCreated }, { "type", _ => _.Type }, { "status", _ => _.Status } }; // validate if (BasePagerModel.IsInvalid(model, sortExpression.Keys, out var errFields)) { return(APIResponse.BadRequest(errFields)); } var user = await GetUserFromDb(); var query = ( from h in DbContext.UserFinHistory where h.UserId == user.Id && ( h.Status == UserFinHistoryStatus.Manual || h.Status == UserFinHistoryStatus.Processing || h.Status == UserFinHistoryStatus.Completed || h.Status == UserFinHistoryStatus.Failed ) select h ); var page = await query.PagerAsync( model.Offset, model.Limit, sortExpression.GetValueOrDefault(model.Sort), model.Ascending ); var nowTime = DateTime.UtcNow; var list = from i in page.Selected select new FiatHistoryViewItem() { Type = i.Type.ToString().ToLower(), Status = ( i.Status == UserFinHistoryStatus.Completed ? 2 // success : i.Status == UserFinHistoryStatus.Failed ? 3 // cancelled/failed : 1 // pending ), Comment = i.Comment, Src = i.Source, SrcAmount = i.SourceAmount, Dst = i.Destination, DstAmount = i.DestinationAmount, Date = ((DateTimeOffset)i.TimeCreated).ToUnixTimeSeconds(), } ; return(APIResponse.Success( new FiatHistoryView() { Items = list.ToArray(), Limit = model.Limit, Offset = model.Offset, Total = page.TotalCount, } )); }