Пример #1
0
 /// <summary>
 /// Creates an instance of assignment from the data record in the database.
 /// </summary>
 /// <param name="myRecord">Single row of record.</param>
 /// <returns>An assignment.</returns>
 private static Assignment FillRecord(IDataRecord myRecord)
 {
     Assignment myAssignment = new Assignment();
     myAssignment.AssignmentId = myRecord.GetInt32(myRecord.GetOrdinal("AssignmentID"));
     myAssignment.ATitle = myRecord.GetString(myRecord.GetOrdinal("ATitle"));
     myAssignment.AFileLocation = myRecord.GetString(myRecord.GetOrdinal("AFileLocation"));
     myAssignment.DueDate = myRecord.GetDateTime(myRecord.GetOrdinal("DueDate"));
     myAssignment.AssignedDate = myRecord.GetDateTime(myRecord.GetOrdinal("AssignedDate"));
     return myAssignment;
 }
Пример #2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            Assignment assignment = new Assignment();
            assignment.AssignmentId = -1;
            assignment.CourseId = Session["courseID"].ToString();
            //Check whether or not the title is specified.
            if (txtboxAssignmentTitle.Text == String.Empty)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "errorTitle",
                                                   "alert('Please provide title of the assignment!!!');", true);
            }
            else
            {
                if (txtboxDueDate.Text == String.Empty)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "errorTitle",
                                                       "alert('Please provide due date of the assignment submission!!!');",
                                                       true);
                }
                else
                {
                    assignment.ATitle = txtboxAssignmentTitle.Text;
                    assignment.DueDate = Convert.ToDateTime(txtboxDueDate.Text);
                    //Check whether or not there is valid file to upload.
                    if (fileuploadAssignment.HasFile)
                    {
                        if (fileuploadAssignment.PostedFile.ContentType.ToLower() == "application/pdf"
                            || fileuploadAssignment.PostedFile.ContentType.ToLower() == "application/msword")
                        {
                            //Append date and time in the filename to make it unique.
                            string filename = Path.GetFileNameWithoutExtension(fileuploadAssignment.FileName) +
                                              DateTime.Now.ToString("_yyyy_mm_dd_HH_mm_ss");
                            string extension = Path.GetExtension(fileuploadAssignment.FileName);
                            string directory = Server.MapPath("~/CourseMaterials/" + Session["courseID"] + "/Assignment");
                            //Create directory if no folder to save the lecture note
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }
                            assignment.AFileLocation = directory + "/" + filename + extension;
                            fileuploadAssignment.SaveAs(assignment.AFileLocation);
                            ClientScript.RegisterStartupScript(this.GetType(), "successUpload",
                                                               "alert('Uploaded successfully!!!');", true);
                            AssignmentController.Save(assignment);
                            Response.Redirect("~/InstructorSite/formManageAssignment.aspx");
                        }
                        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);
                    }
                }

            }
        }
Пример #3
0
        /// <summary>
        /// Saves an assignment in the database.
        /// </summary>
        /// <param name="myAssignment">The assignment to store.</param>
        /// <returns>The new assignment id if the assignment is new in the database or the existing ID when an record was updated.</returns>
        public static int Save(Assignment myAssignment)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString))
            {
                SqlCommand myCommand = new SqlCommand("spInsertUpdateAssignment", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@assignmentID", myAssignment.AssignmentId);
                myCommand.Parameters.AddWithValue("@courseID", myAssignment.CourseId);
                myCommand.Parameters.AddWithValue("@atitle", myAssignment.ATitle);
                myCommand.Parameters.AddWithValue("afilelocation", myAssignment.AFileLocation);
                myCommand.Parameters.AddWithValue("@duedate", myAssignment.DueDate);
                myCommand.Parameters.AddWithValue("@assigneddate", myAssignment.AssignedDate);

                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;
        }
Пример #4
0
 public static int Save(Assignment myAssignment)
 {
     return AssignmentDA.Save(myAssignment);
 }