public async Task <LabCourse> Create(LabCourseCreate courseIn)
        {
            var course = LabCourse.FromCreate(courseIn);
            await _labCourses.InsertOneAsync(course);

            return(course);
        }
Exemple #2
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, LabCourseUpdate update)
        {
            if (!await _authenticationService.CheckAccess(authToken, "courseMgr"))
            {
                return(Unauthorized());
            }

            LabCourse course = await _labCourseService.Get(id);

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

            _labCourseService.Update(course, update);

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

            return(Ok());
        }
Exemple #3
0
        public string deleteAll(string id)
        {
            LabCourse c = new LabCourse();

            c.id = int.Parse(id);
            r.deleteAll(c);
            return("");
        }
Exemple #4
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));
        }
Exemple #5
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());
        }
Exemple #6
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());
        }
 public async Task AddGroup(LabCourse toUpdate, string groupId)
 {
     if (toUpdate.LabGroups == null)
     {
         toUpdate.LabGroups = new List <string>();
         toUpdate.LabGroups.Add(groupId);
     }
     else
     {
         toUpdate.LabGroups.Add(groupId);
     }
     await _labCourses.ReplaceOneAsync(labCourse => labCourse.Id == toUpdate.Id, toUpdate);
 }
Exemple #8
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);
        }
Exemple #9
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 void Update(LabCourse original, LabCourseUpdate update) =>
 await _labCourses.ReplaceOneAsync(labCourse => labCourse.Id == original.Id, LabCourse.FromUpdate(original, update));
        public async Task RemoveGroup(LabCourse toUpdate, string groupId)
        {
            toUpdate.LabGroups.Remove(groupId);

            await _labCourses.ReplaceOneAsync(labCourse => labCourse.Id == toUpdate.Id, toUpdate);
        }
 public string deleteAll(LabCourse c)
 {
     r.deleteAll(c);
     return("");
 }
 public bool insert(LabCourse ll)
 {
     return(l.insert(ll));
 }