Example #1
0
        public async Task <IActionResult> GetOrders()
        {
            FirebaseUser           user  = HttpContext.GetFirebaseUser();
            GetSupplierOrdersQuery model = new GetSupplierOrdersQuery()
            {
                firebaseId = user.UserId
            };

            ResultWrapper <GetSupplierOrdersOutput> result = await _mediator.Send(model);

            return(Ok(result));
        }
Example #2
0
        public Task <ResultWrapper <GetSupplierOrdersOutput> > Handle(GetSupplierOrdersQuery request, CancellationToken cancellationToken)
        {
            ResultWrapper <GetSupplierOrdersOutput> result = new ResultWrapper <GetSupplierOrdersOutput>();


            TUser tUser = _dbContext.TUser.FirstOrDefault(x => x.FireBaseId == request.firebaseId);

            if (tUser == null)
            {
                result.Status  = false;
                result.Message = "cannot find supplier!";
                return(Task.FromResult(result));
            }

            var list = _dbContext.TOrder
                       .Include(x => x.TSupplier)
                       .Where(x => x.TSupplierId == tUser.Id)
                       .Where(x => x.Submited)
                       .Select(tData => new GetSupplierOrdersOutput.OrderItem()
            {
                Id                = tData.Id,
                Title             = tData.Title,
                TotalPayablePrice = tData.TotalPayablePrice,
                Customer          = tData.TUser.FirstName + " " + tData.TUser.LastName,
                Date              = tData.Date
            })
                       .ToList();

            result.Status = true;
            result.Result = new GetSupplierOrdersOutput()
            {
                list = list
            };

            return(Task.FromResult(result));
        }