예제 #1
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());
        }
예제 #2
0
        public async Task <ActionResult <List <LabGroupView> > > Get([FromHeader] string authToken)
        {
            if (!await _authenticationService.CheckAccess(authToken, "groupMgr"))
            {
                return(Unauthorized());
            }

            List <LabGroup> groups = await _labGroupService.Get();

            List <LabGroupView> view = new List <LabGroupView>();


            foreach (LabGroup group in groups)
            {
                LabGroupView temp = LabGroupView.FromGroup(group);

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

                User prof = await _userService.Get(course.ProfessorId);

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

                temp.LabCourseName = prof.FirstName + " " + prof.LastName + " " + course.Semester + " " + course.Year + " " + course.Name;

                if (bench != null)
                {
                    temp.LabBenchName = "Lab " + bench.Lab + " Bench " + bench.BenchNum;
                }

                foreach (string userId in temp.Members)
                {
                    User user = await _userService.Get(userId);

                    temp.MembersNames.Add(user.TechId + " " + user.Username);
                }

                view.Add(temp);
            }

            return(view);
        }
예제 #3
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, string type, OrderUpdate orderIn)
        {
            if (!await _authenticationService.CheckAccess(authToken, "orderMgr"))
            {
                return(Unauthorized());
            }

            Order order = await _orderService.Get(id);

            if (order == null)
            {
                return(NotFound("Order Not Found!"));
            }

            if (type == "onOrder")
            {
                LabGroup group = await _labGroupService.Get(orderIn.GroupId);

                if (!_hostEnvironment.EnvironmentName.Equals("Development", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (string userId in group.Members)
                    {
                        User temp = await _userService.Get(userId);

                        string details = "x" + orderIn.Quantity + " " + orderIn.PartNumber + " from " + orderIn.Url;

                        EmailHelpers.SendOrderPlacedEmail(temp.TechMail, details);
                    }
                }

                orderIn.ShippedUtc = DateTime.UtcNow;
            }
            else if (type == "completed")
            {
                LabGroup group = await _labGroupService.Get(orderIn.GroupId);

                if (!_hostEnvironment.EnvironmentName.Equals("Development", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (string userId in group.Members)
                    {
                        User temp = await _userService.Get(userId);

                        string details = "x" + orderIn.Quantity + " " + orderIn.PartNumber + " from " + orderIn.Url;

                        EmailHelpers.SendOrderPlacedEmail(temp.TechMail, details);
                    }
                }
                orderIn.ReceivedUtc = DateTime.UtcNow;
            }
            else if (type == "rejected")
            {
                LabGroup group = await _labGroupService.Get(orderIn.GroupId);

                group.BudgetBalance = group.BudgetBalance + (orderIn.UnitCost * orderIn.Quantity);

                group.Transactions.Add(new Transaction(
                                           null,
                                           "Add",
                                           "Order Rejected",
                                           (orderIn.UnitCost * orderIn.Quantity),
                                           DateTime.UtcNow
                                           ));

                _labGroupService.Update(group, group.Id);

                if (!_hostEnvironment.EnvironmentName.Equals("Development", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (string userId in group.Members)
                    {
                        User temp = await _userService.Get(userId);

                        EmailHelpers.SendOrderRejectedEmail(temp.TechMail);
                    }
                }
            }

            _orderService.Update(order, orderIn);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Order Updated",
                                         "orders",
                                         id,
                                         JsonSerializer.Serialize(Order.FromUpdate(order, orderIn))
                                         ));

            return(Ok());
        }