public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model) { using (db) { var user = db.Users.Find(model.UserId); var note = new Note() { Title = model.Title, Content = model.Content }; user.Notes.Add(note); db.SaveChanges(); } return(Profile(model.UserId)); }
public IActionResult Register(RegisterUserBindingModel model) { var user = new User() { UserName = model.Username, Password = model.Password }; using (var db = new SimpleMvcDbContext()) { db.Users.Add(user); db.SaveChanges(); } return(this.View()); }
public IActionResult Register(RegisterUserBindingModel registerUserBinding) { var user = new User() { Username = registerUserBinding.Username, Password = registerUserBinding.Password }; using (var context = new SimpleMvcDbContext()) { context.Users.Add(user); context.SaveChanges(); } return(View()); }
public IActionResult Profile(AddNoteBindingModel model) { using (var db = new SimpleMvcDbContext()) { var user = db.Users.Find(model.UserId); var note = new Note { Title = model.Title, Content = model.Content, }; user.Notes.Add(note); db.SaveChanges(); return(Profile(model.UserId)); } }
public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model) { using (var context = new SimpleMvcDbContext()) { var user = context.Users.Find(model.UserId); var note = new Note() { Title = model.Title, Content = model.Content }; user.Notes.Add(note); context.SaveChanges(); } return(Profile(model.UserId)); }
public IActionResult Login(LoginUserBindingModel loginUserBinding) { using (var db = new SimpleMvcDbContext()) { var foundUser = db.Users .FirstOrDefault(u => u.Username == loginUserBinding.Username); if (foundUser == null) { return(this.RedirectToAction("/users/login")); } db.SaveChanges(); this.SignIn(foundUser.Username); } return(this.RedirectToAction("/home/index")); }
public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model) { using (SimpleMvcDbContext database = new SimpleMvcDbContext()) { User user = database.Users.FirstOrDefault(u => u.Id == model.UserId); Note note = new Note { Title = model.Title, Content = model.Content }; user.Notes.Add(note); database.SaveChanges(); } return(this.Profile(model.UserId)); }
public IActionResult Register(RegisterUserBindingModel model) { if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password)) { return(this.Register()); } User user = new User { Username = model.Username, Password = model.Password }; using (SimpleMvcDbContext database = new SimpleMvcDbContext()) { database.Users.Add(user); database.SaveChanges(); } return(this.View()); }
public IActionResult Register(RegisterUserBindingModel model) { using (var db = new SimpleMvcDbContext()) { if (db.Users.Any(u => u.Username == model.Username)) { throw new BadRequestException("Username is already in use."); } var user = new User { Username = model.Username, Password = model.Password }; db.Users.Add(user); db.SaveChanges(); } return(this.View()); }