public async Task <ActionResult <List <Dictionary <string, object> > > > Get([FromHeader] string authToken, [FromQuery] string view)
        {
            if (!await _authenticationService.CheckAccess(authToken, "logView"))
            {
                return(Unauthorized());
            }

            List <Dictionary <string, object> > logs = new List <Dictionary <string, object> >();

            if (view == "orders")
            {
                LabGroup group = await _labGroupService.GetByMemberId(AuthenticationHelpers.GetUserIdFromToken(authToken));

                logs = await _logViewService.GetOrderHistory(view, group, _supplierService);
            }

            else if (view == "transactions")
            {
                LabGroup group = await _labGroupService.GetByMemberId(AuthenticationHelpers.GetUserIdFromToken(authToken));

                int i = 1;
                foreach (Transaction t in group.Transactions)
                {
                    Dictionary <string, object> transaction = new Dictionary <string, object>();
                    transaction["action"]      = t.Action;
                    transaction["amount"]      = t.Amount;
                    transaction["description"] = t.Description;
                    if (t.OrderId == string.Empty || t.OrderId == null)
                    {
                        transaction["order"] = null;
                    }
                    else
                    {
                        Order o = await _orderService.Get(t.OrderId);

                        Supplier s = await _supplierService.Get(o.SupplierId);

                        Dictionary <string, object> order = new Dictionary <string, object>();
                        order["placedUtc"]  = o.PlacedUtc;
                        order["partNumber"] = o.PartNumber;
                        if (!(s == null))
                        {
                            order["supplierName"] = s.Name;
                        }
                        order["url"]         = o.Url;
                        transaction["order"] = order;
                    }
                    transaction["utc"] = t.Utc;
                    transaction["key"] = i;
                    logs.Add(transaction);
                    i++;
                }
            }


            return(logs);
        }
예제 #2
0
        public async Task <ActionResult <Dictionary <string, object> > > Get([FromHeader] string authToken, bool thisDoesNothing)
        {
            if (!await _authenticationService.CheckAccess(authToken, "groupView"))
            {
                return(Unauthorized());
            }

            Dictionary <string, object> groupBudget = new Dictionary <string, object>();

            LabGroup group = await _labGroupService.GetByMemberId(AuthenticationHelpers.GetUserIdFromToken(authToken));

            groupBudget["budget"]        = group.Budget;
            groupBudget["budgetBalance"] = group.BudgetBalance;

            return(groupBudget);
        }
예제 #3
0
        public async Task <ActionResult <BudgetRequest> > Get([FromHeader] string authToken)
        {
            if (!await _authenticationService.CheckAccess(authToken, "budgetView"))
            {
                return(Unauthorized());
            }

            BudgetRequest budgetRequest = await _budgetRequestService.Get(await _labGroupService.GetByMemberId(AuthenticationHelpers.GetUserIdFromToken(authToken)));

            if (budgetRequest == null)
            {
                return(BadRequest("No Active Budget Requests!"));
            }

            return(budgetRequest);
        }
예제 #4
0
        public async Task <ActionResult <List <Order> > > Get([FromHeader] string authToken)
        {
            if (!await _authenticationService.CheckAccess(authToken, "orderView"))
            {
                return(Unauthorized());
            }

            LabGroup group = await _labGroupService.GetByMemberId(AuthenticationHelpers.GetUserIdFromToken(authToken));

            var orders = await _orderService.GetByGroupId(group.Id);

            if (orders == null || orders.Count == 0)
            {
                return(NotFound());
            }

            return(orders);
        }
예제 #5
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, bool inOut, [FromQuery] string techId)
        {
            if (!await _authenticationService.CheckAccess(authToken, "benchMgr"))
            {
                return(Unauthorized());
            }

            LabBench bench = await _labBenchService.Get(id);

            if (bench == null)
            {
                return(NotFound());
            }

            if (inOut)
            {
                User user = await _userService.GetByTechId(techId);

                if (user == null)
                {
                    return(NotFound());
                }

                LabGroup group = await _labGroupService.GetByMemberId(user.Id);

                if (group == null)
                {
                    return(NotFound());
                }

                _labBenchService.CheckInOut(bench, group.Id, "Taken");

                _labGroupService.UpdateBench(group, id);

                await _logService.Create(new Log(
                                             null,
                                             AuthenticationHelpers.GetUserIdFromToken(authToken),
                                             DateTime.UtcNow,
                                             "Document modified.",
                                             "labBenches",
                                             id,
                                             JsonSerializer.Serialize(LabBench.FromCheckInOut(bench, group.Id, "Taken"))
                                             ));
            }
            else
            {
                LabGroup group = await _labGroupService.GetByBenchId(bench.Id);

                if (group == null)
                {
                    return(NotFound());
                }

                _labGroupService.UpdateBench(group, null);

                _labBenchService.CheckInOut(bench, null, "Available");

                await _logService.Create(new Log(
                                             null,
                                             AuthenticationHelpers.GetUserIdFromToken(authToken),
                                             DateTime.UtcNow,
                                             "Document modified.",
                                             "labBenches",
                                             id,
                                             JsonSerializer.Serialize(LabBench.FromCheckInOut(bench, null, "Available"))
                                             ));
            }

            return(Ok());
        }