Exemplo n.º 1
0
        /// <summary>
        /// Adds an assignment to an assignment group
        /// </summary>
        /// <param name="assignmentGroupID"></param>
        /// <param name="assignmentData"></param>
        /// <returns></returns>
        public AssignmentDTO AddAssignment(int courseInstanceID, AddAssignmentViewModel assignmentData)
        {
            // Validating the data
            assignmentData.ValidateAssignmentVM();

            // Fetching the group (throws an error if not found)
            AssignmentGroup group = _assignmentGroups.GetAssignmentGroupByID(assignmentData.AssignmentGroupID);

            // Creating new assignment entity
            Assignment newAssignment = new Assignment
            {
                AssignmentGroupID = group.ID,
                CourseInstanceID  = courseInstanceID,
                Name = assignmentData.Name
            };

            // Adding the new entity to the repo
            _assignments.Add(newAssignment);

            // Saving changes
            _uow.Save();

            return(new AssignmentDTO
            {
                AssignmentGroupID = group.ID,
                ID = newAssignment.ID,
                Name = newAssignment.Name,
                CourseInstanceID = courseInstanceID,
                Weight = (double)group.Weight / group.GradedAssignments
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Store([FromBody] AssignmentGroup assignmentGroup)
        {
            _context.Add(assignmentGroup);
            await _context.SaveChangesAsync();

            return(Created(HttpContext.Request.Path.ToUriComponent(), assignmentGroup));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            AssignmentGroup assignmentGroup = db.AssignmentGroups.Find(id);

            db.AssignmentGroups.Remove(assignmentGroup);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create()
        {
            var assignmentGroup = new AssignmentGroup {
                IsNew = true
            };

            _assignmentGroupRepository.InsertAndCommit(assignmentGroup);
            return(Json(new { Id = assignmentGroup.Id }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fetches all assignments belonging to an assignment group
        /// </summary>
        /// <param name="assignmentGroupID"></param>
        /// <returns></returns>
        public List <AssignmentDTO> GetAssignmentsInGroup(int assignmentGroupID)
        {
            //Making sure the group exists
            AssignmentGroup group = _assignmentGroups.GetAssignmentGroupByID(assignmentGroupID);

            // Fetching corresponding assignments
            List <AssignmentDTO> assignments = _assignments.GetGroupAssignments(assignmentGroupID);

            return(assignments);
        }
 public ActionResult Edit([Bind(Include = "OrganizationID,CourseID,ReviewAppID,AssignmentAppID")] AssignmentGroup assignmentGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assignmentGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(assignmentGroup));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Fetches a single assignment group by ID
        /// </summary>
        /// <param name="assignmentGroupID"></param>
        /// <returns></returns>
        public AssignmentGroupDTO GetAssignmentGroup(int assignmentGroupID)
        {
            AssignmentGroup result = _assignmentGroups.GetAssignmentGroupByID(assignmentGroupID);


            AssignmentGroupDTO transObject = result.GetAssignmentGroupDTO();

            transObject.Assignments = GetAssignmentsInGroup(assignmentGroupID);

            return(transObject);
        }
 /// <summary>
 /// Returns an assignment group data transfer object through its entity class
 /// </summary>
 /// <param name="group"></param>
 /// <returns></returns>
 public static AssignmentGroupDTO GetAssignmentGroupDTO(this AssignmentGroup group)
 {
     return(new AssignmentGroupDTO
     {
         ID = group.ID,
         Name = group.Name,
         Weight = group.Weight,
         GradedAssignments = group.GradedAssignments,
         CourseInstanceID = group.CourseInstanceID
     });
 }
Exemplo n.º 9
0
 public IActionResult EditGroup(AssignmentGroup group)
 {
     if (ModelState.IsValid)
     {
         groupRepository.SaveAssignmentGroup(group);
         return(RedirectToAction(nameof(Groups)));
     }
     else
     {
         return(View());
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Helper function for adding a user to assignments, adds him to a single assignment in course
        /// </summary>
        public void AssignNewGroupForUserInAssignment(string userId, int assignmentId)
        {
            var highestAssignmentProblemGroupNumber = _db.AssignmentGroups.Where(x => x.AssignmentId == assignmentId).OrderByDescending(y => y.GroupNumber).ToList();

            if (highestAssignmentProblemGroupNumber != null && highestAssignmentProblemGroupNumber.Any())
            {
                var assGroup = new AssignmentGroup {
                    UserId       = userId,
                    AssignmentId = assignmentId,
                    GroupNumber  = highestAssignmentProblemGroupNumber[0].GroupNumber + 1
                };
                _db.AssignmentGroups.Add(assGroup);
            }
        }
        // GET: AssignmentGroups/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AssignmentGroup assignmentGroup = db.AssignmentGroups.Find(id);

            if (assignmentGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(assignmentGroup));
        }
Exemplo n.º 12
0
        private void ValidateGroups(AppUser user, AssignmentGroup group)
        {
            var groups    = groupRepository.AssociatedGroups(user);
            var validated = false;

            foreach (var g in groups)
            {
                if (g.GroupId == group.Id)
                {
                    validated = true;
                    break;
                }
            }
            if (!validated)
            {
                ModelState.AddModelError("", "User does not belong to group");
            }
        }
Exemplo n.º 13
0
        private static async Task AssignTicketAsync(AllocationResponse allocationResponse, Match match)
        {
            var assignmentGroup = new AssignmentGroup();

            assignmentGroup.Assignment = new Assignment
            {
                Connection = $"{allocationResponse.Address}:{allocationResponse.Ports[0].Port}"
            };
            foreach (var ticket in match.Tickets)
            {
                assignmentGroup.TicketIds.Add(ticket.Id);
            }

            var assignTicketsRequest = new AssignTicketsRequest();

            assignTicketsRequest.Assignments.Add(assignmentGroup);

            using var backendChannel = GrpcChannel.ForAddress(BackendUrl);
            var backendClient = new BackendServiceClient(backendChannel);

            await backendClient.AssignTicketsAsync(assignTicketsRequest);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Adds an assignment group to a course instance
        /// </summary>
        /// <param name="courseInstanceID"></param>
        /// <param name="groupData"></param>
        /// <returns></returns>
        public AssignmentGroupDTO AddAssignmentGroup(int courseInstanceID, AddAssignmentGroupViewModel groupData)
        {
            groupData.ValidateAssignmentGroupVM();

            // Fetching the course (throws an error if not found)
            CourseInstance course = _courseInstances.GetCourseInstanceByID(courseInstanceID);

            // Fetching the assignments in the group
            List <AssignmentGroupDTO> courseAssignmentGroups = GetAssignmentGroups(courseInstanceID);


            // Adding the new group's weight to the list
            double totalWeight = courseAssignmentGroups.CalculateAssignmentGroupWeight() + groupData.Weight;

            // Illegal if new group weight goes above the maximum
            if (totalWeight > 100)
            {
                throw new CoursesAPIException(ErrorCodes.ILLEGAL_ASSIGNMENT_GROUP_WEIGHT);
            }

            // New group to add
            AssignmentGroup newGroup = new AssignmentGroup
            {
                CourseInstanceID  = courseInstanceID,
                Name              = groupData.Name,
                GradedAssignments = groupData.GradedAssignments,
                Weight            = groupData.Weight
            };


            _assignmentGroups.Add(newGroup);

            _uow.Save();

            AssignmentGroupDTO groupDTO = newGroup.GetAssignmentGroupDTO();

            return(groupDTO);
        }
Exemplo n.º 15
0
        public static async Task <bool> AssignAsync(List <Match> matches)
        {
            foreach (var match in matches)
            {
                var ticketIds = new List <string>();
                foreach (var ticket in match.Tickets)
                {
                    ticketIds.Add(ticket.Id);
                }

                // TODO: Add Agones connection
                var conn        = $"{rnd.Next(0, 255)}.{rnd.Next(0, 255)}.{rnd.Next(0, 255)}.{rnd.Next(0, 255)}:2222";
                var assignments = new AssignmentGroup()
                {
                    Assignment = new Assignment()
                    {
                        Connection = conn
                    }
                };
                assignments.TicketIds.AddRange(ticketIds);

                var request = new AssignTicketsRequest();
                request.Assignments.Add(assignments);

                var status = await backendServiceClient.AssignTicketsAsync(request);

                if (status == null)
                {
                    Console.WriteLine("AssignTickets failed for match " + match.MatchId);
                    return(false);
                }

                Console.WriteLine("Assigned server " + conn + " to match " + match.MatchId);
                return(true);
            }
            Console.WriteLine("No matches to assign");
            return(false);
        }
        public ActionResult Create([Bind(Include = "AssignmentAppID")] AssignmentGroup assignmentGroup)
        {
            assignmentGroup.OrganizationID = Session["OrganizationID"].ToString();
            assignmentGroup.CourseID       = (int)Session["CourseID"];
            assignmentGroup.ReviewAppID    = Session["AssignmentName"].ToString();
            //check if assignmentgroup already exists
            var dbGroup = db.AssignmentGroups.Find(assignmentGroup.OrganizationID, assignmentGroup.CourseID, assignmentGroup.ReviewAppID);

            if (dbGroup == null && ModelState.IsValid)
            {
                //create new
                db.AssignmentGroups.Add(assignmentGroup);
                db.SaveChanges();
            }
            else
            {
                //edit old
                db.Entry(assignmentGroup).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("ReviewAdmin", "Tool"));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Match assignments
        /// </summary>
        private void MatchAssignments(AssignmentGroup group, SortedDictionary <int, ComplexAssignment> insert, SortedDictionary <int, ComplexAssignment> remove)
        {
            // Try to match all the statements in the group
            foreach (var node in group.AllNodes)
            {
                ComplexAssignment na = new ComplexAssignment();
                na.Nodes  = node;
                na.Op     = null;
                na.Index  = int.MaxValue;
                na.Length = 0;
                na.Real   = true;

                // Create the real part
                string rpart = "";
                foreach (var a in group.RealByNode(node))
                {
                    if (na.Op == null)
                    {
                        na.Op = a.Op;
                        rpart = a.Value;
                    }
                    else
                    {
                        if (a.Op == na.Op)
                        {
                            if (rpart.Length > 0)
                            {
                                rpart += " + ";
                            }
                            rpart += a.Value;
                        }
                        else
                        {
                            if (rpart.Length > 0)
                            {
                                rpart += " - ";
                            }
                            else
                            {
                                rpart += "-";
                            }
                            if (a.Value.Contains('+') || a.Value.Contains('-'))
                            {
                                rpart += "(" + a.Value + ")";
                            }
                            else
                            {
                                rpart += a.Value;
                            }
                        }
                    }

                    // Keep the first assignment to insert
                    if (a.Index < na.Index)
                    {
                        na.Index = a.Index;
                    }
                    remove.Add(a.Index, a);
                }

                // Create the imaginary part
                string ipart = "";
                foreach (var a in group.ImaginaryByNode(node))
                {
                    if (na.Op == null)
                    {
                        na.Op = a.Op;
                        ipart = a.Value;
                    }
                    else
                    {
                        if (a.Op == na.Op)
                        {
                            if (ipart.Length > 0)
                            {
                                ipart += " + ";
                            }
                            ipart += a.Value;
                        }
                        else
                        {
                            if (ipart.Length > 0)
                            {
                                ipart += " - ";
                            }
                            else
                            {
                                ipart += "-";
                            }
                            if (a.Value.Contains('+') || a.Value.Contains('-'))
                            {
                                ipart += "(" + a.Value + ")";
                            }
                            else
                            {
                                ipart += a.Value;
                            }
                        }
                    }

                    // Keep the first assignment to insert
                    if (a.Index < na.Index)
                    {
                        na.Index = a.Index;
                    }
                    remove.Add(a.Index, a);
                }

                // Build the value
                if (string.IsNullOrEmpty(ipart))
                {
                    na.Value = $"cstate.Matrix[{node.Item1}, {node.Item2}] {na.Op} {rpart};";
                }
                else
                {
                    if (string.IsNullOrEmpty(rpart))
                    {
                        rpart = "0.0";
                    }
                    na.Value = $"cstate.Matrix[{node.Item1}, {node.Item2}] {na.Op} new Complex({rpart}, {ipart});";
                }
                na.Length = na.Value.Length;
                insert.Add(na.Index, na);
            }
        }