public void UpdateUser(User editedUser) { try { using (var context = new JsonContext()) { context.ObjUser.AddOrUpdate(editedUser); context.SaveChanges(); } } catch (Exception) { //Log error } }
public User CreateUser(User newUser) { try { using (var context = new JsonContext()) { context.ObjUser.Add(newUser); context.SaveChanges(); } } catch (Exception) { //Log error newUser = null; } return(newUser); }
public void DeleteUser(int id) { try { using (var context = new JsonContext()) { var user = context.ObjUser.Find(id); //fetching the user with Id if (user != null) { context.ObjUser.Remove(user); //deleting from db context.SaveChanges(); } } } catch (Exception) { //Log error } }