Exemplo n.º 1
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"));
            }
        }
Exemplo n.º 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"));
         }
     }
 }
Exemplo n.º 3
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 }));
     }
 }
Exemplo n.º 4
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"));
         }
     }
 }
Exemplo n.º 5
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));
 }