Esempio n. 1
0
    private static async Task <IResult> ForUser(int userid, IHoldingService holdingService)
    {
        if (userid <= 0)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "user id"))));
        }
        var holdings = await holdingService.GetForUserAsync(userid);

        return(Results.Ok(holdings));
    }
Esempio n. 2
0
    private static async Task <IResult> PrivatelyHeld(int beanid, IHoldingService holdingService)
    {
        if (beanid <= 0)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "bean id"))));
        }
        var held = await holdingService.BeansHeldByBeanAsync(beanid);

        return(Results.Ok(held));
    }
Esempio n. 3
0
    private static async Task <IResult> SellToExchange(int holdingid, long quantity, IHoldingService holdingService, IBeanService beanService)
    {
        var result = await beanService.SellToExchangeAsync(holdingid, quantity);

        if (result.Successful)
        {
            return(Results.Ok());
        }
        return(Results.BadRequest(result.ErrorMessage()));
    }
Esempio n. 4
0
 private static async Task <IResult> Count(int userid, int?beanid, IHoldingService holdingService)
 {
     if (userid <= 0)
     {
         return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "user id"))));
     }
     if (beanid.HasValue && beanid.Value <= 0)
     {
         return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "bean id"))));
     }
     return(Results.Ok(await holdingService.HoldingCountAsync(userid, beanid)));
 }
Esempio n. 5
0
    private static async Task <IResult> Basis(int userid, IHoldingService holdingService)
    {
        if (userid <= 0)
        {
            return(Results.BadRequest(new ApiError(string.Format(Strings.Invalid, "user id"))));
        }
        var holdings = await holdingService.GetForUserAsync(userid);

        if (holdings is null || !holdings.Any())
        {
            return(Results.Ok(0M));
        }
        return(Results.Ok(holdings.Sum(x => x.Quantity * x.Price)));
    }
Esempio n. 6
0
    private static async Task <IResult> UserHistory(int userid, int?days, IBeanService beanService, IHoldingService holdingService)
    {
        if (userid <= 0)
        {
            return(Results.BadRequest(string.Format(Strings.Invalid, "user id")));
        }
        if (!days.HasValue)
        {
            days = int.MaxValue;
        }
        var ids = await beanService.BeanIdsAsync(userid);

        List <BeanHistoryModel> ret = new();

        foreach (var id in ids)
        {
            var history = await beanService.HistoryAsync(id, days.Value);

            if (history is not null)
            {
                history.Basis = await holdingService.GetCostBasisAsync(userid, id);

                history.Quantity = (await holdingService.SummaryAsync(userid, history.BeanId))?.Quantity ?? 0;
                ret.Add(history);
            }
        }
        return(Results.Ok(ret));
    }
Esempio n. 7
0
 public HoldingController(IHoldingService service, IMapper mapper, ILogger logger)
 {
     _service = service;
     _mapper  = mapper;
     _logger  = logger;
 }