public ActionResult DeleteNote(int noteId) { User currentUser = GetCurrentUser(); if (currentUser == null || !UserHasLoggedIn(currentUser.Id)) { return(View("LogIn", new LogInModel())); } using (DrawMapModel context = new DrawMapModel()) { Note note = context.Notes.SingleOrDefault(n => n.Id == noteId); if (note == null || note.UserId != currentUser.Id) { ViewBag.ErrorMessage = "Note with id = '" + noteId + "' does not exist or it is unavailable for the current user"; return(View("Error")); } context.Notes.Remove(note); context.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult LogIn(string email, string password) { using (DrawMapModel context = new DrawMapModel()) { User dbUser = context.Users.SingleOrDefault(u => u.Email == email); if (dbUser == null) { dbUser = new User { Email = email, Password = password }; context.Users.Add(dbUser); context.SaveChanges(); } else if (dbUser.Password != password) { return(View("Login", new LogInModel { HasError = true, ErrorMessage = "User with the same login exists, but the password is incorrect" })); } Response.Cookies.Add(new HttpCookie("authorization", String.Concat(email, " - ", password))); Session.Add(dbUser.Id.ToString(), true); return(RedirectToAction("Index")); } }
//private ActionResult ReturnErrorView(string message) //{ // return //} public ActionResult AddNote(string name, string content) { User currentUser = GetCurrentUser(); if (currentUser == null) { return(View("Error")); } using (DrawMapModel context = new DrawMapModel()) { context.Notes.Add(new Note { Name = name, Content = content, UserId = currentUser.Id }); context.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult LogIn(string email, string password) { using (DrawMapModel context = new DrawMapModel()) { User dbUser = context.Users.SingleOrDefault(u => u.Email == email); if (dbUser == null) { context.Users.Add(new User { Email = email, Password = password }); context.SaveChanges(); } else if (dbUser.Password != password) { return(View("Error")); } Response.Cookies.Add(new HttpCookie("authorization", String.Concat(email, " - ", password))); return(RedirectToAction("Index")); } }
public ActionResult RenameNote(int noteId, string name) { User currentUser = GetCurrentUser(); if (currentUser == null) { return(View("Error")); } using (DrawMapModel context = new DrawMapModel()) { Note note = context.Notes.SingleOrDefault(n => n.Id == noteId); if (note == null || note.UserId != currentUser.Id) { return(View("Error")); } note.Name = name; context.SaveChanges(); return(RedirectToAction("Index")); } }