/// <summary> /// Creates a profile during user creation phase /// </summary> /// <param name="email"></param> private void CreateProfile(string email) { //Create and Access Permission AccessPermission ap = new AccessPermission() { PublicAccess = true, FriendAccess = true, PublisherAccess = true, MinorAccess = true }; db.AccessPermissions.Add(ap); db.SaveChanges(); //Create new LPProfile object LPProfile lpProfile = new LPProfile(); //Get LPUser LPUser lpUser = db.LPUsers.Where(em => em.Email == email).SingleOrDefault(); //Set Profile UserID lpProfile.UserID = lpUser.UserID; //Add AcessPermission obj lpProfile.AccessPermission = ap; //Add to db db.LPProfiles.Add(lpProfile); db.SaveChanges(); //Proceed to next phase CreateProfileRole(lpUser.UserID); }
public ActionResult DeleteConfirmed(int id) { LPProfile pf = db.LPProfiles.Find(id); db.LPProfiles.Remove(pf); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Creates a role for a user after user and profile are created /// </summary> /// <param name="uid"></param> public void CreateProfileRole(int uid) { LPProfile lp = db.LPProfiles.Where(id => id.UserID == uid).SingleOrDefault(); ProfileRole pr = new ProfileRole(); pr.RoleID = 1; pr.ProfileID = lp.ProfileID; db.ProfileRoles.Add(pr); db.SaveChanges(); }
public ActionResult Create([Bind(Include = "UserID, ProfilePhoto, DisplayRealName, Friends, Followers, Writers")] LPProfile pf) { if (ModelState.IsValid) { db.LPProfiles.Add(pf); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Index")); }
public ActionResult Delete(int?id) { if (id == null) { return(HttpNotFound()); } LPProfile pf = db.LPProfiles.Find(id); if (pf == null) { return(HttpNotFound()); } return(View(pf)); }
public ActionResult Edit([Bind(Include = "ProfileID,UserID,PseudonymID,Birthdate,PhoneNumber,LPDescription,ProfilePhoto,DisplayRealName,Friends,Followers,Writers,Pseudonym")] LPProfile lPProfile) { try { if (ModelState.IsValid) { //db.Entry(lPProfile).State = EntityState.Modified; lprepo.SetModified(lPProfile); lprepo.Save(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Failed to edit Profile"); } ViewBag.UserID = new SelectList(db.LPUsers, "UserID", "Email", lPProfile.UserID); return(View(lPProfile)); }
// GET: LPProfiles/Edit/5 public ActionResult Edit() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); LPProfile lPProfile = lprepo.Get(lpCurrentUser.UserID); if (lpCurrentUser == null) { return(HttpNotFound()); } ViewBag.UserID = new SelectList(db.LPUsers, "UserID", "Email", lpCurrentUser.UserID); return(View(lPProfile)); }
// GET: LPProfiles/Details/5 public ActionResult Details() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); //Get the current user's profile based on the user ID LPProfile lPProfile = lprepo.Get(lpCurrentUser.UserID); if (lPProfile == null) { return(HttpNotFound()); } return(View(lPProfile)); }
/// <summary> /// Allows a user to download a file out of the database /// </summary> /// <param name="id"></param> /// <returns> The file in the original format it was uploaded as</returns> public ActionResult Download(int?id) { //Check if logged in ==> Should be caught by [Authorize] but just in case if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser((string)currentUser.Email); //Get the LPProfile LPProfile lpProfile = GetLPProfile(lpCurrentUser.UserID); Writing wr = db.Writings.Find(id); if (wr == null) { return(HttpNotFound()); } //If the ProfileIDs don't match redirect to an error page if (wr.ProfileID != lpProfile.ProfileID) { return(RedirectToAction("DownloadError", "Error")); } UTF8Encoding encoding = new UTF8Encoding(); byte[] contentAsBytes = wr.Document; if (wr.DocType == "HTML" || wr.DocType == ".HTML") { this.HttpContext.Response.ContentType = "application/force-download"; this.HttpContext.Response.AddHeader("Content-Disposition", "filename=" + wr.WritingFileName); } else if (wr.DocType == "DOC" || wr.DocType == ".DOC") { this.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } else if (wr.DocType == "ODT" || wr.DocType == ".ODT") { this.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } else if (wr.DocType == "PDF" || wr.DocType == ".PDF") { this.HttpContext.Response.ContentType = "application/pdf"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } else { this.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } this.HttpContext.Response.Buffer = true; this.HttpContext.Response.Clear(); this.HttpContext.Response.OutputStream.Write(contentAsBytes, 0, contentAsBytes.Length); this.HttpContext.Response.OutputStream.Flush(); this.HttpContext.Response.End(); return(View()); }