protected void btnSubmit_Click(object sender, EventArgs e) { string sname = Session["Username"].ToString(); int assignmentId = Convert.ToInt32(Request.QueryString["AssignmentID"]); Submission studentassignment = new Submission(); studentassignment.Student.SId = sname; studentassignment.Assignment.AssignmentId = assignmentId; studentassignment.SubmissionDate = DateTime.Now; if (fileuploadSubmission.HasFile) { if (fileuploadSubmission.PostedFile.ContentType.ToLower() == "application/pdf" || fileuploadSubmission.PostedFile.ContentType.ToLower() == "application/msword") { string filename = sname; string extension = Path.GetExtension(fileuploadSubmission.FileName); string directory = Server.MapPath("~/CourseMaterials/" + Session["courseID"] + "/Assignment/Assignment" + assignmentId); //Create directory if no folder to save the lecture note if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } studentassignment.FileLocation = directory + "/" + filename + extension; fileuploadSubmission.SaveAs(studentassignment.FileLocation); ClientScript.RegisterStartupScript(this.GetType(), "successUpload", "alert('Uploaded successfully!!!');", true); SubmissionController.Save(studentassignment); Response.Redirect(String.Format("~/Presentation/formAssignmentDetail.aspx?AssignmentID={0}", assignmentId)); } else //If the file format is invalid. { ClientScript.RegisterStartupScript(this.GetType(), "fileFormatError", "alert('File format error: Only pdf or doc files are allowed!!!');", true); } } else //If the path doesn't contain any file { ClientScript.RegisterStartupScript(this.GetType(), "failUpload", "alert('Please specify the file to upload.!!!');", true); } }
/// <summary> /// Saves a Submission in the database. /// </summary> /// <param name="mySubmission">The Submission to store.</param> /// <returns>The new ID if the Submission is new in the database or the existing ID when an record was updated.</returns> public static int Save(Submission mySubmission) { int result = 0; using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString)) { SqlCommand myCommand = new SqlCommand("spInsertUpdateAssignmentSubmissionGrade", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@sid", mySubmission.Student.SId); myCommand.Parameters.AddWithValue("@assignmentID", mySubmission.Assignment.AssignmentId); myCommand.Parameters.AddWithValue("@submissiondate", mySubmission.SubmissionDate); myCommand.Parameters.AddWithValue("@filelocation", mySubmission.FileLocation); myCommand.Parameters.AddWithValue("@grade", mySubmission.Grade); DbParameter retValue = myCommand.CreateParameter(); retValue.Direction = ParameterDirection.ReturnValue; myCommand.Parameters.Add(retValue); myConnection.Open(); myCommand.ExecuteNonQuery(); result = Convert.ToInt32(retValue.Value); myConnection.Close(); } return result; }
protected void btnSave_Click(object sender, EventArgs e) { SubmissionList slist = new SubmissionList(); foreach (DataListItem item in dlGradeAssignmentByInstructor.Items) { Submission s = new Submission(); s.Student.SId = ((Label) item.FindControl("lblStudentID")).Text; s.Grade = Convert.ToDecimal(((TextBox) item.FindControl("txtBoxGrade")).Text); s.Assignment.AssignmentId = assignmentId; slist.Add(s); } SubmissionController.Save(slist); slist.Clear(); Response.Redirect("~/Presentation/formAssignment.aspx"); }
/// <summary> /// Transfer submission information to submission DAL. /// </summary> /// <param name="mySubmission">The Submission to store.</param> /// <returns>The new ID if the Submission is new in the database or the existing ID when an record was updated.</returns> public static int Save(Submission mySubmission) { return SubmissionDA.Save(mySubmission); }