Esempio n. 1
0
        public LectureNoteViewModel Update(LectureNoteEditModel lectureNote)
        {
            LectureNote updateLectureNote = _mapper.Map <LectureNoteEditModel, LectureNote>(lectureNote);
            LectureNote updatednote       = _unitOfWork.LectureNotes.Update(updateLectureNote);

            return(_mapper.Map <LectureNote, LectureNoteViewModel>(updatednote));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an instance of LectureNote from the data record in the database.
        /// </summary>
        /// <param name="myRecord">Single row of record.</param>
        /// <returns>An LectureNote.</returns>
        private static LectureNote FillRecord(IDataRecord myRecord)
        {
            LectureNote myLectureNote = new LectureNote();

            //myLectureNote.CourseId = myRecord.GetString(myRecord.GetOrdinal("CourseID"));
            myLectureNote.LectureId     = myRecord.GetInt32(myRecord.GetOrdinal("LectureID"));
            myLectureNote.LTitle        = myRecord.GetString(myRecord.GetOrdinal("LTitle"));
            myLectureNote.LFileLocation = myRecord.GetString(myRecord.GetOrdinal("LFileLocation"));
            return(myLectureNote);
        }
        private async Task UpdateRatingAsync(string postId)
        {
            LectureNote lectureNote = _unitOfWork.LectureNotes.Get(postId);

            if (lectureNote != null)
            {
                lectureNote.AverageRating = _unitOfWork.LectureNoteRatings.GetAverageRating(postId);
                _unitOfWork.LectureNotes.Update(lectureNote);
                await _unitOfWork.SaveAsync();
            }
        }
Esempio n. 4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            LectureNote lNote = new LectureNote();

            lNote.LectureId = -1;
            lNote.CourseId  = Session["courseID"].ToString();
            //Check whether or not the title is specified.
            if (txtboxLectureTitle.Text == String.Empty)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "errorTitle",
                                                   "alert('Please provide title of the lecture note!!!');", true);
            }
            else
            {
                lNote.LTitle = txtboxLectureTitle.Text;
                //Check whether or not there is valid file to upload.

                if (fileuploadLectureNote.HasFile)
                {
                    if (fileuploadLectureNote.PostedFile.ContentType.ToLower() == "application/pdf" ||
                        fileuploadLectureNote.PostedFile.ContentType.ToLower() == "application/x-mspowerpoint")
                    {
                        //Append date and time in the filename to make it unique.
                        string filename = Path.GetFileNameWithoutExtension(fileuploadLectureNote.FileName) +
                                          DateTime.Now.ToString("_yyyy_mm_dd_HH_mm_ss");
                        string extension = Path.GetExtension(fileuploadLectureNote.FileName);
                        string directory = Server.MapPath("~/CourseMaterials/" + Session["courseID"] + "/LectureNote");
                        //Create directory if no folder toa save the lecture note
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }
                        lNote.LFileLocation = directory + "/" + filename + extension;
                        fileuploadLectureNote.SaveAs(lNote.LFileLocation);
                        ClientScript.RegisterStartupScript(this.GetType(), "successUpload",
                                                           "alert('Uploaded successfully!!!');", true);
                        LectureNoteController.Save(lNote);
                        Response.Redirect("~/InstructorSite/formManageLectureNote.aspx");
                    }
                    else //If the file format is invalid.
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "fileFormatError",
                                                           "alert('File format error: Only pdf or ppt 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);
                }
            }
        }
Esempio n. 5
0
        // GET: AssignCourse/Delete/5
        public ActionResult DeleteLectureNote(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LectureNote ln = db.LectureNotes.Find(id);

            if (ln == null)
            {
                return(HttpNotFound());
            }
            return(View(ln));
        }
Esempio n. 6
0
        public ActionResult DeleteLectureNoteConfirmed(int id)
        {
            LectureNote ln = db.LectureNotes.Find(id);

            string fullPath = Server.MapPath("~/App_Data/LectureNotes/" + ln.PdfLectureNote);

            if (System.IO.File.Exists(fullPath))
            {
                System.IO.File.Delete(fullPath);
            }

            db.LectureNotes.Remove(ln);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 7
0
        public async Task <LectureNoteViewModel> CreateAsync(LectureNoteViewModel lectureNote)
        {
            LectureNote lectureNoteModel = _mapper.Map <LectureNoteViewModel, LectureNote>(lectureNote);

            lectureNoteModel.Author = await _unitOfWork.UserManager.FindByNameAsync(lectureNote.AuthorUsername);

            lectureNoteModel.AverageRating    = 0.0;
            lectureNoteModel.DateOfCreate     = DateTime.Now;
            lectureNoteModel.DateOfLastChange = DateTime.Now;
            lectureNoteModel.Specialty        = await _specialtyNumberService.CreateSpecialtyNumberAsync(lectureNote.SpecialtyNumber);

            lectureNoteModel = _unitOfWork.LectureNotes.Add(lectureNoteModel);
            await _unitOfWork.SaveAsync();

            return(_mapper.Map <LectureNote, LectureNoteViewModel>(lectureNoteModel));
        }
Esempio n. 8
0
        public ActionResult UploadNote(HttpPostedFileBase PdfLectureNote, string CourseId)
        {
            string path = Server.MapPath("~/App_Data/LectureNotes/");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (PdfLectureNote.ContentLength >= 6000000)
            {
                ViewData["CourseId"] = CourseId;
                ViewData["FileSize"] = PdfLectureNote.ContentLength / 1000000;
                return(View("NewNotes"));
            }

            var supportedTypes = new[] { "pdf" };
            var fileExt        = System.IO.Path.GetExtension(PdfLectureNote.FileName).Substring(1);

            if (!supportedTypes.Contains(fileExt))
            {
                ViewData["CourseId"] = CourseId;
                ViewData["FileType"] = fileExt;
                return(View("NewNotes"));
            }

            Course course = new Course();

            if (PdfLectureNote != null)
            {
                string fileName = Path.GetFileName(PdfLectureNote.FileName);
                PdfLectureNote.SaveAs(path + fileName);
                LectureNote ln = new LectureNote();
                ln.Id             = 0;
                ln.LectureDate    = DateTime.UtcNow;
                ln.PdfLectureNote = fileName;
                course            = db.Courses.ToList().Where(c => c.Id == int.Parse(CourseId)).First();
                ln.Course         = course;
                if (ModelState.IsValid)
                {
                    db.LectureNotes.Add(ln);
                    db.SaveChanges();
                }
            }

            return(View("CourseDetails", course));
        }
Esempio n. 9
0
        /// <summary>
        /// Saves an LectureNote in the database.
        /// </summary>
        /// <param name="myLectureNote">The LectureNote to store.</param>
        /// <returns>The new LectureNote id if the LectureNote is new in the database or the existing ID when an record was updated.</returns>
        public static int Save(LectureNote myLectureNote)
        {
            int result = 0;

            using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString))
            {
                SqlCommand myCommand = new SqlCommand("spInsertUpdateLectureNote", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@courseID", myLectureNote.CourseId);
                myCommand.Parameters.AddWithValue("@ltitle", myLectureNote.LTitle);
                myCommand.Parameters.AddWithValue("@lfilelocation", myLectureNote.LFileLocation);

                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);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets an instance of LectureNote.
        /// </summary>
        /// <param name="lectureID">A unique ID of the lecture.</param>
        /// <returns>A LectureNote if it matches, otherwise null.</returns>
        public static LectureNote GetItem(int lectureID)
        {
            LectureNote myLectureNote = null;

            using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString))
            {
                SqlCommand myCommand = new SqlCommand("spSelectSingleLectureNote", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@lid", lectureID);

                myConnection.Open();
                using (SqlDataReader myDataReader = myCommand.ExecuteReader())
                {
                    if (myDataReader.Read())
                    {
                        myLectureNote = FillRecord(myDataReader);
                    }
                    myDataReader.Close();
                }
                myConnection.Close();
            }
            return(myLectureNote);
        }
        public ActionResult NewLectureNote(int Id = 0, int SubjectId = 0)
        {
            if (Id == 0 && SubjectId == 0)
            {
                return(Redirect("/Admin/Assignments"));
            }
            if (Id != 0)
            {
                using (EastWoodEntities db = new EastWoodEntities())
                {
                    var note = db.LectureNotes.Where(w => w.LectureNoteid == Id).FirstOrDefault();
                    note.Subject     = note.Subject;
                    note.Attachments = db.Attachments.
                                       Where(w => w.AttachmentReferenceId == note.LectureNoteid && w.AttachmentReferenceType == AttachmentReferenceTypes.LECTURE_NOTE)
                                       .ToList();
                    return(View(note));
                }
            }
            LectureNote sub = new LectureNote();

            sub.SubjectId = SubjectId;
            return(View(sub));
        }
Esempio n. 12
0
        public LectureNoteViewModel GetById(string id)
        {
            LectureNote lectureNote = _unitOfWork.LectureNotes.Get(id);

            return(_mapper.Map <LectureNote, LectureNoteViewModel>(lectureNote));
        }
Esempio n. 13
0
 public static int Save(LectureNote myLectureNote)
 {
     return(LectureNoteDA.Save(myLectureNote));
 }
        public ActionResult NewLectureNote(LectureNote lectureNote)
        {
            using (EastWoodEntities db = new EastWoodEntities())
            {
                //  Get all files from Request object
                HttpFileCollectionBase files       = Request.Files;
                List <Attachment>      attachments = new List <Attachment>();

                // create Item
                if (lectureNote.LectureNoteid != 0)
                {
                    var a = db.LectureNotes.Where(w => w.LectureNoteid == lectureNote.LectureNoteid).FirstOrDefault();
                    a.LectureNoteName        = lectureNote.LectureNoteName;
                    a.LectureNoteDescription = lectureNote.LectureNoteDescription;
                    a.LectureNoteSubmittedOn = DateTime.Now;
                    a.LectureNoteDate        = lectureNote.LectureNoteDate;
                }
                else
                {
                    lectureNote.LectureNoteSubmittedOn = DateTime.Now;
                    db.LectureNotes.Add(lectureNote);
                }
                db.SaveChanges();

                int fileCount = db.Attachments
                                .Where(w => w.AttachmentReferenceId == lectureNote.LectureNoteid && w.AttachmentReferenceType == AttachmentReferenceTypes.LECTURE_NOTE)
                                .Count();

                if (Request.Files.Count > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFileBase file = files[i];
                        string             fname;

                        // Checking for Internet Explorer
                        if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
                        {
                            string[] testfiles = file.FileName.Split(new char[] { '\\' });
                            fname = testfiles[testfiles.Length - 1];
                        }
                        else
                        {
                            fname = file.FileName;
                        }

                        string[] find      = fname.Split('.');
                        string   extention = find[find.Length - 1];
                        fname = lectureNote.LectureNoteName + "_" + (i + fileCount) + "." + extention;

                        // Get the complete folder path and store the file inside it.
                        var finalName = Path.Combine(Server.MapPath("~/Uploads/"), fname);
                        file.SaveAs(finalName);

                        // Create attachment
                        Attachment attachment = new Attachment();
                        attachment.AttachmentName          = fname;
                        attachment.AttachmentUrl           = "/Uploads/" + fname;
                        attachment.AttachmentReferenceType = AttachmentReferenceTypes.LECTURE_NOTE;
                        attachment.AttachmentReferenceId   = lectureNote.LectureNoteid;
                        attachment.AttachmentFileSize      = file.ContentLength;
                        db.Attachments.Add(attachment);
                        db.SaveChanges();
                    }
                }
            }


            return(Redirect("/Admin/LectureNotes/" + lectureNote.SubjectId));
        }