Пример #1
0
 public SaleService(ISaleRepository saleRepository, IUserRepository userRepository, IBeanRepository beanRepository, IOptions <AppSettings> settings,
                    ITimeSpanConverter timeSpanConverter)
 {
     _saleRepository   = saleRepository;
     _userRepository   = userRepository;
     _beanRepository   = beanRepository;
     _longtermTimespan = timeSpanConverter.Convert(settings.Value.LongTermSpan);
 }
Пример #2
0
    public static async Task <IResult> ById(int userid, ITimeSpanConverter converter, IOptions <AppSettings> settings, ISaleService saleService)
    {
        if (userid <= 0)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "user id"))));
        }
        var longTermSpan = converter.Convert(settings.Value.LongTermSpan);

        if (longTermSpan == TimeSpan.Zero)
        {
            longTermSpan = TimeSpan.FromDays(365);
        }
        var sales = await saleService.GetForUserAsync(userid);

        if (sales is not null && sales.Any())
        {
            sales.ForEach(x => x.LongTerm = x.SaleDate - x.PurchaseDate >= longTermSpan);
        }
        return(Results.Ok(sales));
    }