Esempio n. 1
0
    public async Task <BeanHistoryModel?> HistoryAsync(int beanid, int days = int.MaxValue)
    {
        var bean = await _beanRepository.ReadAsync(beanid);

        if (days <= 0 || bean is null)
        {
            return(null);
        }

        var cutoff                     = days == int.MaxValue ? default : (DateTime.UtcNow - TimeSpan.FromDays(days - 1)).Date;
                               var ret = new BeanHistoryModel
                               {
                                   BeanId    = bean.Id,
                                   BeanName  = bean.Name,
                                   ImageName = bean.Filename,
                                   Price     = bean.Price,
                                   Basis     = CostBasis.Default,
                                   Quantity  = 0,
                                   Days      = days,
                                   Movements = Array.Empty <MovementModel>()
                               };
                               var sql       = $"select * from Movements where BeanId={beanid} and CAST(MovementDate as Date) >= '{cutoff:yyyy-MM-dd}' order by MovementDate";
                               var movements = (await _movementReposotory.GetAsync(sql));

                               ret.Movements = movements.ToModels <MovementModel, MovementEntity>().ToArray();
                               return(ret);
    }
Esempio n. 2
0
    public async Task <IEnumerable <MovementModel> > GetAsync()
    {
        var entities = await _movementRepository.GetAsync();

        return(Finish(entities));
    }