示例#1
0
 protected void SaveStudent(object sender, EventArgs e)
 {
     var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
     var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
     var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
     IdentityResult result = manager.Create(user, Password.Text);
     if (result.Succeeded)
     {
         // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
         string code = manager.GenerateEmailConfirmationToken(user.Id);
         string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
         manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
         using (ResourceContext db = new ResourceContext())
         {
             MentorStudent ms = new MentorStudent
             {
                 MentorId = User.Identity.GetUserId(),
                 StudentId = user.Id,
                 DateInvited = DateTime.Now
             };
             db.StudentsContext.Add(ms);
             db.SaveChanges();
         }
         Response.Redirect("Students");
     }
 }
示例#2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (ResourceContext db = new ResourceContext())
     {
         string currUser = User.Identity.GetUserId();
         var ms = db.StudentsContext.Where(r => r.MentorId == currUser).Select(r => r.StudentId).ToList();
     }
 }
示例#3
0
 protected void DownloadMaterial(object sender, EventArgs e)
 {
     Response.ContentType = DetailType.Text;
     Response.AppendHeader("Content-Disposition", "attachment; filename=" + DetailFilename.Text);
     Response.TransmitFile(Server.MapPath(DetailSource.Value));
     Response.End();
     using (ResourceContext db = new ResourceContext())
     {
         int materialId = Convert.ToInt32(DetailId.Value);
         Material material = db.MaterialsContext.Find(materialId);
         material.DownloadTimes = material.DownloadTimes + 1;
         db.Entry(material).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     int lectureId = Convert.ToInt32(Request.QueryString["Id"]);
     using (ResourceContext db = new ResourceContext())
     {
         Lecture lecture = db.LecturesContext.Find(lectureId);
         LectureTitle.Attributes.Add("value", lecture.Title);
         NotesTextBox.Text = lecture.Notes;
         MaterialsList.DataSource = db.MaterialsContext.Where(m => m.LectureId == lectureId).ToList();
         MaterialsList.DataBind();
         if (MaterialsList.Rows.Count > 0)
         {
             MaterialsList.UseAccessibleHeader = true;
             MaterialsList.HeaderRow.TableSection = TableRowSection.TableHeader;
         }
         MaterialsList.GridLines = GridLines.None;
     }
 }
示例#5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     int lectureId = Convert.ToInt32(Request.QueryString["Id"]);
     using (ResourceContext db = new ResourceContext())
     {
         Lecture lecture = db.LecturesContext.Find(lectureId);
         LectureTitle.Text = lecture.Title;
         LectureNotes.Text = lecture.Notes;
         DateCreated.Text = lecture.DateCreated.ToString();
         MaterialsList.DataSource = db.MaterialsContext.Where(m => m.LectureId == lectureId).ToList();
         MaterialsList.DataBind();
         if (MaterialsList.Rows.Count > 0)
         {
             MaterialsList.UseAccessibleHeader = true;
             MaterialsList.HeaderRow.TableSection = TableRowSection.TableHeader;
         }
         MaterialsList.GridLines = GridLines.None;
         EditLectureLink.NavigateUrl = "EditLecture.aspx?Id=" + lectureId;
     }
 }
示例#6
0
 protected void SaveLecture(object sender, EventArgs e)
 {
     string savePath = Server.MapPath("~/resources/" + User.Identity.GetUserId() + "/");
     if (!Directory.Exists(savePath))
     {
         Directory.CreateDirectory(savePath);
     }
     if (MaterialInput.HasFiles)
     {
         if (ModelState.IsValid)
         {
             using (ResourceContext db = new ResourceContext())
             {
                 Lecture lecture = new Lecture
                 {
                     Title = LectureTitle.Text,
                     Notes = NotesTextBox.Text,
                     DateCreated = DateTime.Now,
                     AuthorId = User.Identity.GetUserId()
                 };
                 foreach (HttpPostedFile uploadedFile in MaterialInput.PostedFiles)
                 {
                     uploadedFile.SaveAs(Path.Combine(savePath, uploadedFile.FileName));
                     Material material = new Material
                     {
                         Filename = uploadedFile.FileName,
                         ContentType = uploadedFile.ContentType,
                         ContentLength = uploadedFile.ContentLength,
                         DateUploaded = DateTime.Now
                     };
                    lecture.Materials.Add(material);
                 }
                 db.LecturesContext.Add(lecture);
                 db.SaveChanges();
             }
         }
     }
     Response.Redirect("Lectures");
 }
示例#7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     int materialId = Convert.ToInt32(Request.QueryString["Id"]);
     using (ResourceContext db = new ResourceContext())
     {
         DataBind();
         Material material = db.MaterialsContext.Find(materialId);
         Filename.Text = material.Filename;
         string source = "resources/" + material.Lecture.AuthorId + "/" + material.Filename;
         if (material.ContentType.StartsWith("image"))
         {
             RenderedContent.Text = "<img src='" + source + "' />";
         } else if (material.ContentType == "application/pdf")
         {
             RenderedContent.Text = "<embed style='width: 100%; height: 600px;' src='" + source + "' type='application/pdf'>";
         } else if (material.ContentType.StartsWith("video"))
         {
             string sourceTag = "<source src='" + source + "' type='" + material.ContentType + "'>";
             RenderedContent.Text = "<video style='width: 100%; height: auto;' preload='auto' controls>" + sourceTag + "</video>";
         } else if (material.ContentType.StartsWith("audio"))
         {
             string sourceTag = "<source src='" + source + "' type='" + material.ContentType + "'>";
             RenderedContent.Text = "<audio style='width: 100%; height: auto;' preload='auto' controls>" + sourceTag + "</audio>";
         } else
         {
             RenderedContent.Text = "<div class='well'>The material is not supported for previewing.</div>";
         }
         DetailFilename.Text = material.Filename;
         DetailLength.Text = material.ContentLength + " bytes";
         DetailType.Text = material.ContentType;
         DetailLecture.Text = material.Lecture.Title;
         DetailLecture.NavigateUrl = "LectureView.aspx?Id=" + material.LectureId;
         DetailSource.Value = source;
         DownloadTimes.Text = "Downloaded " + material.DownloadTimes + " times.";
         DetailId.Value = materialId.ToString();
     }
 }