public ActionResult Student_Project_Submission(AspNetStudent_Project stu_project) { int id = Convert.ToInt32(Request.Form["id"]); AspNetStudent_Project student_project = (from p in db.AspNetStudent_Project where p.Id == id select p).SingleOrDefault(); var dbTransaction = db.Database.BeginTransaction(); try { HttpPostedFileBase file = Request.Files["document"]; if (ModelState.IsValid) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/ProjectsSubmission"), fileName); file.SaveAs(path); student_project.SubmittedFileName = fileName; } } student_project.SubmissionStatus = true; student_project.SubmissionDate = DateTime.Now; db.SaveChanges(); dbTransaction.Commit(); } catch (Exception) { dbTransaction.Dispose(); } return(RedirectToAction("Project_Detail", new { id = student_project.ProjectID })); }
public FileResult downloadStudentSubmittedFile(int id) { AspNetStudent_Project Student_Project = db.AspNetStudent_Project.Find(id); var filepath = System.IO.Path.Combine(Server.MapPath("~/App_Data/ProjectsSubmission/"), Student_Project.SubmittedFileName); return(File(filepath, MimeMapping.GetMimeMapping(filepath), Student_Project.SubmittedFileName)); }
public ActionResult Project_Detail(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetStudent_Project aspNetStudentProject = db.AspNetStudent_Project.Where(x => x.ProjectID == id && x.StudentID == StudentID).FirstOrDefault(); if (aspNetStudentProject == null) { return(HttpNotFound()); } return(View(aspNetStudentProject)); }
public ActionResult Project_Detail(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetStudent_Project aspNetStudentProject = db.AspNetStudent_Project.Where(x => x.ProjectID == id).FirstOrDefault(); if (aspNetStudentProject == null) { return(HttpNotFound()); } ViewBag.filename = aspNetStudentProject.SubmittedFileName; return(View(aspNetStudentProject)); }
public ActionResult Create(AspNetProject aspNetProject) { HttpPostedFileBase file = Request.Files["attachment"]; if (ModelState.IsValid) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Projects"), fileName); file.SaveAs(path); aspNetProject.FileName = fileName; } else { aspNetProject.FileName = "-/-"; } if (db.AspNetProjects.Where(x => x.FileName == aspNetProject.FileName).Count() > 0) { TempData["Error"] = "Document already exists kindly change document name"; return(RedirectToAction("Create")); } else { db.AspNetProjects.Add(aspNetProject); db.SaveChanges(); } int ProjectID = db.AspNetProjects.Max(x => x.Id); List <string> StudentIDs = db.AspNetStudent_Subject.Where(s => s.SubjectID == aspNetProject.SubjectID).Select(s => s.StudentID).ToList(); foreach (var item in StudentIDs) { AspNetStudent_Project student_project = new AspNetStudent_Project(); student_project.StudentID = item; student_project.ProjectID = ProjectID; student_project.SubmissionStatus = false; student_project.SubmittedFileName = "-/-"; db.AspNetStudent_Project.Add(student_project); db.SaveChanges(); } /////////////////////////////////////////////////NOTIFICATION///////////////////////////////////// var NotificationObj = new AspNetNotification(); NotificationObj.Description = aspNetProject.Description; NotificationObj.Subject = aspNetProject.Title; NotificationObj.SenderID = User.Identity.GetUserId(); NotificationObj.Time = DateTime.Now; NotificationObj.Url = "/AspNetProject/Details/" + aspNetProject.Id; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); var NotificationID = db.AspNetNotifications.Max(x => x.Id); var students = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.StudentID).ToList(); var users = new List <String>(); foreach (var item in students) { var parentID = db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault(); users.Add(parentID); } var allusers = users.Union(students); foreach (var receiver in allusers) { var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationID; notificationRecieve.UserID = Convert.ToString(receiver); notificationRecieve.Seen = false; db.AspNetNotification_User.Add(notificationRecieve); db.SaveChanges(); } /////////////////////////////////////Email///////////////////////////////////////// var subject = db.AspNetSubjects.Where(x => x.Id == aspNetProject.SubjectID).Select(x => x.SubjectName).FirstOrDefault(); var StudentEmail = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.StudentID).ToList(); var StudentRoll = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.AspNetUser.UserName).ToList(); string[] studentRollList = new string[StudentRoll.Count]; int c = 0; foreach (var item in StudentRoll) { studentRollList[c] = item; c++; } var StudentName = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.AspNetUser.Name).ToList(); string[] studentNamelist = new string[StudentName.Count]; int i = 0; foreach (var item in StudentName) { studentNamelist[i] = item; i++; } var Users = new List <String>(); foreach (var item in StudentEmail) { Users.Add(db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault()); } //Message start //var classe = db.AspNetClasses.Where(p => p.Id == aspNetHomework.ClassId).FirstOrDefault(); Utility obj = new Utility(); obj.SMSToOffitialsp("Dear Principal, Project has been assigned. IPC NGS Preschool, Aziz Avenue, Lahore."); obj.SMSToOffitialsa("Dear Admin, Project has been assigned. IPC NGS Preschool, Aziz Avenue, Lahore."); AspNetMessage oob = new AspNetMessage(); oob.Message = "Dear Parents, The thematic project has been assigned to your child on portal. IPC NGS Preschool, Aziz Avenue, Lahore.";// Title : " + aspNetProject.Title + ", For discription login to Portal please - obj.SendSMS(oob, Users); //Message end List <string> EmailList = new List <string>(); foreach (var sender in Users) { EmailList.Add(db.AspNetUsers.Where(x => x.Id == sender).Select(x => x.Email).FirstOrDefault()); } var j = 0; foreach (var toEmail in EmailList) { try { NotificationObj.Subject = studentNamelist[j] + "(" + studentRollList[j] + ") " + " Subject:" + subject + " Title:" + aspNetProject.Title; j++; string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString(); string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString(); SmtpClient client = new SmtpClient("smtpout.secureserver.net", 25); client.EnableSsl = false; client.Timeout = 100000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(senderEmail, senderPassword); MailMessage mailMessage = new MailMessage(senderEmail, toEmail, NotificationObj.Subject, NotificationObj.Description); mailMessage.CC.Add(new MailAddress(senderEmail)); mailMessage.IsBodyHtml = true; mailMessage.BodyEncoding = UTF8Encoding.UTF8; client.Send(mailMessage); } catch (Exception ex) { } } return(RedirectToAction("Index")); } ViewBag.ClassID = new SelectList(db.AspNetClasses.Where(x => x.SessionID == SessionID), "Id", "ClassName"); ViewBag.SubjectID = new SelectList(db.AspNetSubjects.Where(x => x.AspNetClass.SessionID == SessionID), "Id", "SubjectName", aspNetProject.SubjectID); TempData["Create"] = "Project has been created"; return(View(aspNetProject)); }