Ejemplo n.º 1
0
        protected void SubmitAssignmentButton_OnClick(object sender, EventArgs e)
        {
            if (!FileUploadControl.HasFiles)
            {
                SubmitResponseLabel.Text = "Du kan ikke aflevere uden et dokument";
                return;
            }
            List <string> filepaths = new List <string>();

            foreach (HttpPostedFile document in FileUploadControl.PostedFiles)
            {
                try
                {
                    filepaths.Add("~/filer/afleveringer/" + Path.GetFileName(document.FileName));
                    document.SaveAs(Path.Combine(Server.MapPath("~/filer/afleveringer/"), document.FileName));
                }
                catch (Exception ex)
                {
                    SubmitResponseLabel.Text = "Fejl: " + ex.Message;
                }
            }
            AssignmentDescription assignmentDescription =
                AssignmentDescription.GetByID(Convert.ToUInt32(Request.QueryString["aflever"]));
            Assignment assignment = Assignment.New(assignmentDescription, Session["user"] as Student,
                                                   SubmitCommentTextBox.Text, filepaths);

            Response.Redirect("/afleveringer.aspx?succes=" + assignment.ID);
        }
Ejemplo n.º 2
0
        public void RemoverRemoveAssignmentDescription_ValidParameters_AssignmentDescriptionRemoved()
        {
            // Arrange
            Creator.CreateCourse(Instances.Name, Instances.Description);
            Course course = Course.GetByID(1);

            Creator.CreateAssignmentDescription(course, Instances.Description, Instances.Date, Instances.Filepaths);
            AssignmentDescription assignmentDescription = AssignmentDescription.GetByID(1);

            // Act
            Remover.RemoveAssignmentDescription(assignmentDescription);

            // Assert
            Assert.AreEqual(0, AssignmentDescription.GetAll().Count);
            Assert.AreEqual(0, course.AssignmentDescriptions.Count);
        }
Ejemplo n.º 3
0
        public void RemoverRemoveAssignmentDescription_ValidParameters_AssignmentDescriptionRemoved()
        {
            // Arrange
            var assignmentDescription = AssignmentDescription.New(Instances.Course, Instances.Title, Instances.Description,
                                                                  Instances.Date, Instances.Filepaths);
            var assignmentDescriptionid = assignmentDescription.ID;

            // Act
            assignmentDescription.Remove();

            // Assert
            try
            {
                AssignmentDescription.GetByID(assignmentDescriptionid);
                Assert.Fail();
            }
            catch (InvalidIDException) { }
        }
Ejemplo n.º 4
0
        public void RemoverRemoveAssignment_ValidParameters_AssignmentRemoved()
        {
            // Arrange
            Creator.CreateCourse(Instances.Name, Instances.Description);
            Course course = Course.GetByID(1);

            Creator.CreateAssignmentDescription(course, Instances.Description, Instances.Date, Instances.Filepaths);
            Creator.CreateStudent(Instances.Name, Instances.Username, Instances.Password);
            AssignmentDescription assignmentDescription = AssignmentDescription.GetByID(1);
            Student student = Student.GetByID(2);

            Creator.CreateAssignment(assignmentDescription, student, Instances.Comment, Instances.Filepaths);
            Assignment assignment = Assignment.GetByID(1);

            // Act
            Remover.RemoveAssignment(assignment);

            // Assert
            Assert.AreEqual(0, Assignment.GetAll().Count);
            Assert.AreEqual(0, assignmentDescription.Assignments.Count);
            Assert.AreEqual(0, student.Assignments.Count);
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(Session["user"] is Student))
            {
                Response.Redirect("login.aspx");
            }
            Master.TitelLabelText = "Afleveringer";
            bool hasAssignmentDescriptions = false;

            if (((Student)Session["user"]).Courses.Count > 0)
            {
                hasAssignmentDescriptions = ((Student)Session["user"]).Courses
                                            .Any(course => course.AssignmentDescriptions.Count > 0);
            }
            if (!hasAssignmentDescriptions)
            {
                AssignmentDescriptionsTable.Visible = false;
                SubmitPanel.Visible  = false;
                SuccessPanel.Visible = false;
                HtmlGenericControl alert = new HtmlGenericControl("div");
                alert.Attributes["role"]  = "alert";
                alert.Attributes["class"] = "alert alert-info";
                alert.InnerHtml           = "Du har ikke nogen afleveringer.";
                AlertPanel.Controls.Add(alert);
                return;
            }
            AlertPanel.Visible = false;
            string submitString  = Request.QueryString["aflever"];
            string successString = Request.QueryString["succes"];

            if (submitString == null && successString == null)
            {
                SubmitPanel.Visible  = false;
                SuccessPanel.Visible = false;
                DrawAssignmentDescriptionsTable();
            }
            else if (submitString != null)
            {
                AssignmentDescription assignmentDescription = null;
                try
                {
                    assignmentDescription = AssignmentDescription.GetByID(Convert.ToUInt32(submitString));
                }
                catch (InvalidIDException)
                {
                    Response.Redirect("afleveringer.aspx");
                }
                // Ensure the following:
                // The user is a part of the course which the AssignmentDescription belongs to
                // The user has not already submitted an Assignment
                // The AssignmentDescription is open for submission (it has not expired)
                if (assignmentDescription.Course.Students.All(s => s.ID != ((Student)Session["user"]).ID) ||
                    assignmentDescription.Assignments.Any(a => a.Student.ID == ((Student)Session["user"]).ID) ||
                    assignmentDescription.HasExpired)
                {
                    Response.Redirect("afleveringer.aspx");
                }
                AssignmentDescriptionsTable.Visible = false;
                SuccessPanel.Visible = false;
                DrawSubmitAssignment(assignmentDescription);
            }
            else
            {
                Assignment assignment = null;
                try
                {
                    assignment = Assignment.GetByID(Convert.ToUInt32(successString));
                }
                catch (InvalidIDException)
                {
                    Response.Redirect("afleveringer.aspx");
                }
                if (assignment.Student.ID == ((Student)Session["user"]).ID)
                {
                    AssignmentDescriptionsTable.Visible = false;
                    SubmitPanel.Visible = false;
                    DrawSuccess(assignment);
                }
                else
                {
                    Response.Redirect("afleveringer.aspx");
                }
            }
        }