Esempio n. 1
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, SupplierUpdate supplierIn)
        {
            if (!await _authenticationService.CheckAccess(authToken, "orderMgr"))
            {
                return(Unauthorized());
            }

            var supplier = await _supplierService.Get(id);

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

            _supplierService.Update(supplier, supplierIn);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "suppliers",
                                         id,
                                         JsonSerializer.Serialize(Supplier.FromUpdate(supplier, supplierIn))
                                         ));

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, UserUpdate userIn)
        {
            if (!await _authenticationService.CheckAccess(authToken, "userMgr"))
            {
                return(Unauthorized());
            }

            var user = await _userService.Get(id);

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

            if (!user.Password.Equals(userIn.Password))
            {
                // TODO: Check to verify this works on the stockroom server
                if (!_hostEnvironment.EnvironmentName.Equals("Development", StringComparison.OrdinalIgnoreCase))
                {
                    EmailHelpers.SendPasswordResetEmail(userIn.TechMail, userIn.Password);
                }
                userIn.Password = AuthenticationHelpers.EncrpytPassword(userIn.Password);

                // Kill all active sessions
                await _tokenService.InvalidateUserTokens(user.Id);
            }

            var permDiff = user.Permissions.Except(userIn.Permissions);
            var roleDiff = user.Roles.Except(userIn.Roles);
            var certDiff = user.Certs.Except(userIn.Certs);

            if (permDiff.Count() != 0 || roleDiff.Count() != 0 || certDiff.Count() != 0)
            {
                // Kill all active sessions
                await _tokenService.InvalidateUserTokens(user.Id);
            }

            if (user.CountryCode != null)
            {
                if (!user.CountryCode.Equals(userIn.CountryCode) || !user.PhoneNumber.Equals(userIn.PhoneNumber))
                {
                    userIn.PhoneVerifiedFlag     = false;
                    userIn.PhoneVerificationCode = await SMSHelpers.SendVerificationCode(userIn.CountryCode, userIn.PhoneNumber);
                }
            }

            _userService.Update(user, userIn);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "auth.users",
                                         id,
                                         JsonSerializer.Serialize(ecestockroom_api.Models.Authentication.User.FromUpdate(user, userIn))
                                         ));

            return(Ok());
        }
        public async Task <IActionResult> DeleteCalibration([FromHeader] string authToken, string stockId, string time)
        {
            if (!await _authenticationService.CheckAccess(authToken, "equipmentMgr"))
            {
                return(Unauthorized());
            }

            StockItem item = await _stockItemService.Get(stockId);


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

            DateTime calibrationDate = DateTime.Parse(time).ToUniversalTime();

            Equipment eq = await _equipmentService.GetFromStockId(stockId);

            _stockItemService.RemoveCalibration(eq.Id, item, calibrationDate);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "StockItem modified.",
                                         "equipment",
                                         eq.Id,
                                         JsonSerializer.Serialize(_stockItemService.Get(stockId))
                                         ));

            return(Ok());
        }
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, ToolGroupUpdate groupIn)
        {
            if (!await _authenticationService.CheckAccess(authToken, "stuToolMgr"))
            {
                return(Unauthorized());
            }

            var toolGroup = await _toolService.Get(id);

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

            _toolService.Update(toolGroup, groupIn);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "toolGroups",
                                         id,
                                         JsonSerializer.Serialize(ToolGroup.FromUpdate(toolGroup, groupIn))
                                         ));

            return(Ok());
        }
Esempio n. 5
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, PPEventUpdate update)
        {
            if (!await _authenticationService.CheckAccess(authToken, "ppEventMgr"))
            {
                return(Unauthorized());
            }

            var ppEvent = await _ppEventService.Get(id);

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

            _ppEventService.Update(ppEvent, update);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "pp.events",
                                         id,
                                         JsonSerializer.Serialize(PPEvent.FromUpdate(ppEvent, update))
                                         ));

            return(Ok());
        }
Esempio n. 6
0
        public async Task <ActionResult <List <User> > > Get([FromHeader] string authToken)
        {
            string userId = AuthenticationHelpers.GetUserIdFromToken(authToken);

            User user = await _userService.Get(userId);

            if (user.ProPoints != null)
            {
                List <Dictionary <string, object> > eventsAttended = new List <Dictionary <string, object> >();

                foreach (PPUserEntry entry in user.ProPoints)
                {
                    Dictionary <string, object> userEntry = new Dictionary <string, object>();
                    PPEvent eventt = await _ppEventService.Get(entry.EventId);

                    userEntry["eventName"]   = eventt.Name;
                    userEntry["checkInUtc"]  = entry.CheckInUtc;
                    userEntry["checkOutUtc"] = entry.CheckOutUtc;
                    userEntry["points"]      = entry.Points;
                    eventsAttended.Add(userEntry);
                }
                return(Ok(eventsAttended));
            }

            return(NotFound());
        }
Esempio n. 7
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, LabBenchUpdate benchIn)
        {
            if (!await _authenticationService.CheckAccess(authToken, "benchMgr"))
            {
                return(Unauthorized());
            }

            LabBench bench = await _labBenchService.Get(id);

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

            _labBenchService.Update(bench, benchIn);

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

            return(Ok());
        }
Esempio n. 8
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, LabGroupUpdate update)
        {
            if (!await _authenticationService.CheckAccess(authToken, "groupMgr"))
            {
                return(Unauthorized());
            }

            LabGroup group = await _labGroupService.Get(id);

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

            _labGroupService.Update(group, update);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "labGroups",
                                         id,
                                         JsonSerializer.Serialize(LabGroup.FromUpdate(group, update))
                                         ));

            return(Ok());
        }
        public async Task <IActionResult> UpdateCalibrations([FromHeader] string authToken, string stockId, CalibrationCreate cal)
        {
            if (!await _authenticationService.CheckAccess(authToken, "equipmentMgr"))
            {
                return(Unauthorized());
            }

            StockItem item = await _stockItemService.Get(stockId);

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

            Equipment eq = await _equipmentService.GetFromStockId(stockId);

            Calibration calibration = Calibration.FromCreate(AuthenticationHelpers.GetUserIdFromToken(authToken), cal);

            _stockItemService.AddCalibration(eq.Id, item, calibration);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "StockItem modified.",
                                         "equipment",
                                         eq.Id,
                                         JsonSerializer.Serialize(_stockItemService.Get(stockId))
                                         ));

            return(Ok());
        }
Esempio n. 10
0
        public async Task <IActionResult> Delete([FromHeader] string authToken, string id)
        {
            if (!await _authenticationService.CheckAccess(authToken, "ppEventMgr"))
            {
                return(Unauthorized());
            }

            var ppEvent = await _ppEventService.Get(id);

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

            await _ppEventService.Delete(id);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document deleted.",
                                         "pp.events",
                                         id,
                                         null
                                         ));

            return(Ok());
        }
        public async Task <IActionResult> Delete([FromHeader] string authToken, string stockId)
        {
            if (!await _authenticationService.CheckAccess(authToken, "equipmentMgr"))
            {
                return(Unauthorized());
            }

            StockItem item = await _stockItemService.Get(stockId);

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

            Equipment eq = await _equipmentService.GetFromStockId(stockId);

            await _stockItemService.Delete(stockId);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "StockItem deleted.",
                                         "equipment",
                                         eq.Id,
                                         JsonSerializer.Serialize(item)
                                         ));

            return(Ok());
        }
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, RoleUpdate roleIn)
        {
            if (!await _authenticationService.CheckAccess(authToken, "roleMgr"))
            {
                return(Unauthorized());
            }

            var role = await _roleService.Get(id);

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

            _roleService.Update(id, roleIn);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "auth.roles",
                                         id,
                                         JsonSerializer.Serialize(Role.FromUpdate(id, roleIn))
                                         ));

            return(Ok());
        }
        public async Task <IActionResult> CheckQuiz([FromHeader] string authToken, List <Dictionary <string, string> > completedQuiz)
        {
            if (!await _authenticationService.CheckAccess(authToken, "certView"))
            {
                return(Unauthorized());
            }

            User user = await _userService.Get(AuthenticationHelpers.GetUserIdFromToken(authToken));

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

            int numCorrect = 0;

            foreach (Dictionary <string, string> answer in completedQuiz)
            {
                QuizQuestion question = await _quizQuestionService.Get(answer["id"]);

                if (question.CorrectAnswer == answer["answerChoice"])
                {
                    numCorrect++;
                }
            }

            if (numCorrect < 7)
            {
                return(BadRequest("You scored under a 70%, please try again"));
            }
            else
            {
                if (user.Certs == null)
                {
                    user.Certs = new List <string>();
                }

                user.Certs.Add("61e49344c9828fb8c104f09b");

                user.Roles.Add("611fcd612cec2947ae2693b0");

                user.Permissions.Add("612036892cec2947ae2693e6");
                user.Permissions.Add("6120464d2cec2947ae2693fe");
                user.Permissions.Add("6120464d2cec2947ae269400");
                user.Permissions.Add("612048372cec2947ae269402");
                user.Permissions.Add("61268b352cec2947ae26942d");
                user.Permissions.Add("6126f55b2cec2947ae269453");
                user.Permissions.Add("6138d1f15e5ae5a54af905e3");
                user.Permissions.Add("614de8e274ad73e6ce9f07ae");
                user.Permissions.Add("61db5d523fb8d66a6bbdde39");
                user.Permissions.Add("61db606a3fb8d66a6bbdde43");

                _userService.Update(user.Id, user);

                await _tokenService.InvalidateUserTokens(user.Id);

                return(Ok("Great Work! You Passed with a " + (numCorrect * 10) + "%!"));
            }
        }
Esempio n. 14
0
        public async Task <ActionResult <Order> > Create([FromHeader] string authToken, bool stockroom, OrderCreate create)
        {
            if (stockroom)
            {
                if (!await _authenticationService.CheckAccess(authToken, "orderMgr"))
                {
                    return(Unauthorized());
                }

                Order created = await _orderService.CreateStockroom(create);

                await _logService.Create(new Log(
                                             null,
                                             AuthenticationHelpers.GetUserIdFromToken(authToken),
                                             DateTime.UtcNow,
                                             "Order Placed",
                                             "orders",
                                             created.Id,
                                             JsonSerializer.Serialize(created)
                                             ));

                return(Ok(created));
            }
            else
            {
                if (!await _authenticationService.CheckAccess(authToken, "orderView"))
                {
                    return(Unauthorized());
                }

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

                Order created = await _orderService.Create(create, group.Id);

                group.BudgetBalance = group.BudgetBalance - (created.UnitCost * created.Quantity);

                group.Transactions.Add(new Transaction(
                                           created.Id,
                                           "Remove",
                                           "Order Submitted",
                                           (created.UnitCost * created.Quantity),
                                           DateTime.UtcNow
                                           ));

                _labGroupService.Update(group, group.Id);

                await _logService.Create(new Log(
                                             null,
                                             AuthenticationHelpers.GetUserIdFromToken(authToken),
                                             DateTime.UtcNow,
                                             "Order Placed",
                                             "orders",
                                             created.Id,
                                             JsonSerializer.Serialize(created)
                                             ));

                return(Ok(created));
            }
        }
        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);
        }
Esempio n. 16
0
        public async Task <ActionResult <LabGroup> > Create([FromHeader] string authToken, LabGroupCreate create)
        {
            if (!await _authenticationService.CheckAccess(authToken, "groupMgr"))
            {
                return(Unauthorized());
            }

            List <string> members = new List <string>();

            foreach (string techId in create.Members)
            {
                User temp = await _userService.GetByTechId(techId);

                members.Add(temp.Id);
            }

            LabCourse course = await _labCourseService.Get(create.LabCourseId);

            LabGroupCreate editCreate = create;

            editCreate.Members       = members;
            editCreate.Budget        = course.InitialBudget;
            editCreate.BudgetBalance = course.InitialBudget;
            editCreate.GroupNumber   = (course.LabGroups == null) ?  1 : course.LabGroups.Count + 1;
            editCreate.Transactions  = new List <Transaction>();
            editCreate.Transactions.Add(new Transaction(null, "Add", "Initial Budget", course.InitialBudget, DateTime.UtcNow));

            LabGroup created = await _labGroupService.Create(editCreate);

            await _labCourseService.AddGroup(course, created.Id);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Group created.",
                                         "labGroups",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            foreach (string id in created.Members)
            {
                User temp = await _userService.Get(id);

                temp.Permissions.Add("61db5dde3fb8d66a6bbdde3b");
                temp.Permissions.Add("61db59a03fb8d66a6bbdde34");
                temp.Permissions.Add("61db5a813fb8d66a6bbdde36");

                await _tokenService.InvalidateUserTokens(temp.Id);

                _userService.Update(temp.Id, temp);
            }

            return(Ok(created));
        }
        public async Task <ActionResult> SwipeOut([FromHeader] string authToken, string techId, string eventId)
        {
            if (!await _authenticationService.CheckAccess(authToken, "ppSwipe"))
            {
                return(Unauthorized());
            }

            User user = await _userService.GetByTechId(techId);

            PPEvent ppEvent = await _ppEventService.Get(eventId);

            if (user == null)
            {
                return(NotFound("tech id not found"));
            }

            if (ppEvent == null)
            {
                return(NotFound("pro point event not found"));
            }

            PPUserEntry userEvent = user.ProPoints.Find(entry => entry.EventId == eventId);

            if (userEvent == null)
            {
                return(Problem("user never checked in"));
            }

            if (userEvent.CheckOutUtc != null)
            {
                return(Problem("user already checked out"));
            }

            DateTime now     = DateTime.UtcNow;
            TimeSpan elapsed = now - userEvent.CheckInUtc;
            int      hours   = (int)Math.Round(elapsed.TotalHours);
            int      points  = (hours * ppEvent.HourlyPointRate) + ppEvent.BasePointRate;

            userEvent.CheckOutUtc = now;
            userEvent.Points      = points;

            _userService.Update(user.Id, user);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "User checked out for Pro Point Event.",
                                         "auth.users",
                                         user.Id,
                                         JsonSerializer.Serialize(user)
                                         ));

            return(Ok());
        }
Esempio n. 18
0
        public async Task <IActionResult> Delete([FromHeader] string authToken, string id)
        {
            if (!await _authenticationService.CheckAccess(authToken, "groupMgr"))
            {
                return(Unauthorized());
            }

            LabGroup group = await _labGroupService.Get(id);

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

            LabCourse course = await _labCourseService.Get(group.LabCourseId);

            if (group.Members != null)
            {
                foreach (string memberId in group.Members)
                {
                    User temp = await _userService.Get(memberId);

                    temp.Permissions.Remove("61db5dde3fb8d66a6bbdde3b");
                    temp.Permissions.Remove("61db59a03fb8d66a6bbdde34");
                    temp.Permissions.Remove("61db5a813fb8d66a6bbdde36");

                    await _tokenService.InvalidateUserTokens(memberId);

                    _userService.Update(temp.Id, temp);
                }
            }

            LabBench bench = await _labBenchService.Get(group.LabBenchId);

            if (bench != null)
            {
                _labBenchService.CheckInOut(bench, null, "Available");
            }
            await _labCourseService.RemoveGroup(course, id);

            await _labGroupService.Delete(id);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document deleted.",
                                         "labGroup",
                                         id,
                                         null
                                         ));

            return(Ok());
        }
Esempio n. 19
0
        public async Task <IActionResult> Delete([FromHeader] string authToken, string id)
        {
            if (!await _authenticationService.CheckAccess(authToken, "courseMgr"))
            {
                return(Unauthorized());
            }

            LabCourse course = await _labCourseService.Get(id);

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

            if (course.LabGroups != null)
            {
                foreach (string labgroupId in course.LabGroups)
                {
                    LabGroup group = await _labGroupService.Get(labgroupId);

                    foreach (string memberId in group.Members)
                    {
                        User temp = await _userService.Get(memberId);

                        if (temp != null)
                        {
                            temp.Permissions.Remove("61db5dde3fb8d66a6bbdde3b");
                            temp.Permissions.Remove("61db59a03fb8d66a6bbdde34");
                            temp.Permissions.Remove("61db5a813fb8d66a6bbdde36");

                            _userService.Update(temp.Id, temp);
                        }
                    }

                    await _labGroupService.Delete(labgroupId);
                }
            }

            await _labCourseService.Delete(id);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document deleted.",
                                         "labCourses",
                                         id,
                                         null
                                         ));

            return(Ok());
        }
Esempio n. 20
0
        public async Task <ActionResult <List <Dictionary <string, object> > > > Get([FromHeader] string authToken, bool active)
        {
            if (!await _authenticationService.CheckAccess(authToken, "orderView"))
            {
                return(Unauthorized());
            }

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

                List <Order> orders = await _orderService.GetActiveByGroupId(group.Id);

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

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

                foreach (Order order in orders)
                {
                    Dictionary <string, object> o = new Dictionary <string, object>();

                    o["description"] = order.Description;
                    o["partNumber"]  = order.PartNumber;
                    o["quantity"]    = order.Quantity;
                    o["unitCost"]    = order.UnitCost;
                    o["url"]         = order.Url;
                    o["status"]      = order.Status;
                    o["placedUtc"]   = order.PlacedUtc;
                    o["shippedUtc"]  = order.ShippedUtc;
                    o["receivedUtc"] = order.ReceivedUtc;

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

                    if (s != null)
                    {
                        o["supplierName"] = s.Name;
                    }

                    activeOrders.Add(o);
                }

                return(activeOrders);
            }

            return(NotFound());
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
        public async Task <ActionResult <Supplier> > Create([FromHeader] string authToken, SupplierCreate supplier)
        {
            if (!await _authenticationService.CheckAccess(authToken, "orderMgr"))
            {
                return(Unauthorized());
            }

            Supplier created = await _supplierService.Create(supplier);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "suppliers",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(supplier));
        }
Esempio n. 24
0
        public async Task <ActionResult <LabBench> > Create([FromHeader] string authToken, LabBenchCreate bench)
        {
            if (!await _authenticationService.CheckAccess(authToken, "benchMgr"))
            {
                return(Unauthorized());
            }

            LabBench created = await _labBenchService.Create(bench);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "labBenches",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(created));
        }
        public async Task <ActionResult <Role> > Create([FromHeader] string authToken, RoleCreate role)
        {
            if (!await _authenticationService.CheckAccess(authToken, "roleMgr"))
            {
                return(Unauthorized());
            }

            Role created = await _roleService.Create(role);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "auth.roles",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(role));
        }
Esempio n. 26
0
        public async Task <ActionResult <LabCourse> > Create([FromHeader] string authToken, LabCourseCreate create)
        {
            if (!await _authenticationService.CheckAccess(authToken, "courseMgr"))
            {
                return(Unauthorized());
            }

            LabCourse created = await _labCourseService.Create(create);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Course created.",
                                         "labCourses",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(created));
        }
        public async Task <ActionResult <ToolGroup> > Create([FromHeader] string authToken, ToolGroupCreate tool)
        {
            if (!await _authenticationService.CheckAccess(authToken, "stuToolMgr"))
            {
                return(Unauthorized());
            }

            ToolGroup created = await _toolService.Create(tool);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "toolGroups",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(tool));
        }
Esempio n. 28
0
        public async Task <ActionResult <PPEvent> > Create([FromHeader] string authToken, PPEventCreate create)
        {
            if (!await _authenticationService.CheckAccess(authToken, "ppEventMgr"))
            {
                return(Unauthorized());
            }

            PPEvent created = await _ppEventService.Create(create);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "pp.events",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(create));
        }
        public async Task <ActionResult <LabGroup> > Create([FromHeader] string authToken, QuizQuestionCreate create)
        {
            if (!await _authenticationService.CheckAccess(authToken, "userMgr"))
            {
                return(Unauthorized());
            }

            QuizQuestion created = await _quizQuestionService.Create(create);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Quiz Question created.",
                                         "quizQuestions",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));



            return(Ok(created));
        }
Esempio n. 30
0
        public async Task <ActionResult <BudgetRequest> > Create([FromHeader] string authToken, BudgetRequestCreate budgetRequest)
        {
            if (!await _authenticationService.CheckAccess(authToken, "announceView"))
            {
                return(Unauthorized());
            }

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

            BudgetRequest created = await _budgetRequestService.Create(budgetRequest, group.Id);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "budgetRequests",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(budgetRequest));
        }