Example #1
0
 //View
 public ActionResult ViewNote(int id)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         Note note = ne.Notes.Find(id);
         if (note.shared == true)
         {
             ViewBag.noteDetails = ne.Notes.Where(x => x.id == id).ToList();
             return(View(note));
         }
         else
         {
             if (Session["email"] != null)
             {
                 if (Session["email"].ToString() == note.email)
                 {
                     ViewBag.noteDetails = ne.Notes.Where(x => x.id == id).ToList();
                     return(View(note));
                 }
                 else
                 {
                     return(RedirectToAction("Dashboard", "Note"));
                 }
             }
             else
             {
                 return(RedirectToAction("Login", "User"));
             }
         }
     }
 }
Example #2
0
 public ActionResult Edit(int id, Note note)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         if (Session["email"] == null)
         {
             return(RedirectToAction("Login", "User"));
         }
         else
         {
             if (note.image != null)
             {
                 String fileName = Path.GetFileNameWithoutExtension(note.ImageFile.FileName);
                 String fileExt  = Path.GetExtension(note.ImageFile.FileName);
                 fileName   = fileName + DateTime.Now.ToString("ddmmyyyyhhmmss") + fileExt;
                 note.image = "~/Images/" + fileName;
                 fileName   = Path.Combine(Server.MapPath("~/Images"), fileName);
                 note.ImageFile.SaveAs(fileName);
             }
             ne.Notes.Attach(note);
             ne.Entry(note).Property(x => x.title).IsModified   = true;
             ne.Entry(note).Property(x => x.content).IsModified = true;
             note.email = Session["email"].ToString();
             ne.SaveChanges();
             return(RedirectToAction("Dashboard", "Note"));
         }
     }
 }
Example #3
0
        public ActionResult Create(Note note)
        {
            if (Session["email"] == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            else
            {
                using (NoteAppEntities ne = new NoteAppEntities())
                {
                    note.email = Session["email"].ToString();

                    if (note.ImageFile != null)
                    {
                        String fileName = Path.GetFileNameWithoutExtension(note.ImageFile.FileName);
                        String fileExt  = Path.GetExtension(note.ImageFile.FileName);
                        fileName   = fileName + DateTime.Now.ToString("ddmmyyyyhhmmss") + fileExt;
                        note.image = "~/Images/" + fileName;
                        fileName   = Path.Combine(Server.MapPath("~/Images"), fileName);
                        note.ImageFile.SaveAs(fileName);
                    }

                    ne.Notes.Add(note);
                    ne.SaveChanges();
                }
                return(RedirectToAction("Dashboard"));
            }
        }
Example #4
0
 //Edit
 public ActionResult Edit(int id)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         if (Session["email"] == null)
         {
             return(RedirectToAction("Login", "User"));
         }
         else
         {
             return(View(ne.Notes.Where(x => x.id == id).FirstOrDefault()));
         }
     }
 }
Example #5
0
 //Search
 public ActionResult Search(String keyword)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         if (Session["email"] == null)
         {
             return(RedirectToAction("Login", "User"));
         }
         else
         {
             var session = Session["email"].ToString();
             var notes   = ne.Notes.Where(x => x.email == session && x.title.Contains(keyword)).ToList();
             return(View(notes));
         }
     }
 }
Example #6
0
 //Dashboard
 public ActionResult Dashboard()
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         if (Session["email"] == null)
         {
             return(RedirectToAction("Login", "User"));
         }
         else
         {
             //var notes = ne.Notes.SqlQuery("SELECT * FROM dbo.notes WHERE email='" + Session["email"] + "'").ToList();
             var session = Session["email"].ToString();
             var notes   = ne.Notes.Where(x => x.email == session).ToList();
             return(View(notes));
         }
     }
 }
Example #7
0
 public ActionResult Login(User user)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         var auth = ne.Users.Where(x => x.email == user.email && x.password == user.password).Count();
         if (auth == 0)
         {
             ViewBag.Message = "Incorrect email/password.  Please try again.";
             return(View("Login", user));
         }
         else
         {
             Session["email"] = user.email;
             return(RedirectToAction("Dashboard", "Note"));
         }
     }
 }
Example #8
0
 //Toggle Sharing
 public ActionResult ToggleSharing(int id)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         Note note = ne.Notes.Find(id);
         if (note.shared == true)
         {
             note.shared = false;
             ne.SaveChanges();
         }
         else
         {
             note.shared = true;
             ne.SaveChanges();
         }
         return(RedirectToAction("ViewNote", "Note", new { id = id }));
     }
 }
Example #9
0
 //Delete
 public ActionResult Delete(int id)
 {
     using (NoteAppEntities ne = new NoteAppEntities())
     {
         if (Session["email"] == null)
         {
             return(RedirectToAction("Login", "User"));
         }
         else
         {
             Note note = ne.Notes.Find(id);
             ne.Notes.Remove(note);
             ne.SaveChanges();
             if (note.image != null)
             {
                 String imagePath = Request.MapPath(note.image);
                 System.IO.File.Delete(imagePath);
             }
             return(RedirectToAction("Dashboard"));
         }
     }
 }
Example #10
0
 public ActionResult Register(User user)
 {
     if (ModelState.IsValid)
     {
         using (NoteAppEntities ne = new NoteAppEntities())
         {
             var auth = ne.Users.Where(x => x.email == user.email).Count();
             if (auth == 1)
             {
                 ViewBag.Message = "An account is already associated with this email.  Please try again.";
                 return(View("Register", user));
             }
             else
             {
                 ne.Users.Add(user);
                 ne.SaveChanges();
                 ModelState.Clear();
                 user            = null;
                 ViewBag.Message = "Account created!";
             }
         }
     }
     return(View(user));
 }