Esempio n. 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");
     }
 }
Esempio n. 2
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();
     }
 }
Esempio n. 3
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");
 }