public int EditUser(int id, UserModel user) { using (FilmDataContext ctx = new FilmDataContext()) { DataObject.EF.User userToEdit = new DataObject.EF.User(); userToEdit = ctx.Users.Where(u => u.UserID == id).FirstOrDefault(); if (userToEdit != null) { userToEdit.UserName = user.UserName; userToEdit.Name = user.Name; userToEdit.Password = user.Password; userToEdit.Phone = user.Phone; userToEdit.Birthday = user.Birthday; userToEdit.Gender = user.Gender; userToEdit.isAdmin = user.isAdmin; userToEdit.status = user.status; return(ctx.SaveChanges()); } else { return(0); } } }
public int AddUser(UserModel user) { using (FilmDataContext ctx = new FilmDataContext()) { if (user == null) { return(-1); } //Create actor DataObject.EF.User _tUser = new DataObject.EF.User() { UserID = user.UserID, UserName = user.UserName, Birthday = user.Birthday, Email = user.Email, Gender = user.Gender, Phone = user.Phone, Name = user.Name, Password = user.Password, isAdmin = user.isAdmin, status = true // AccessDate = user.AccessDate, // AccessToken = user.AccessToken }; ctx.Users.Add(_tUser); return(ctx.SaveChanges()); } }
public int DeleteUser(int id) { using (FilmDataContext ctx = new FilmDataContext()) { DataObject.EF.User userToDelete = ctx.Users.Where(u => u.UserID == id).FirstOrDefault(); if (userToDelete != null) { userToDelete.status = false; return(ctx.SaveChanges()); } else { return(0); } } }
public int setRole(int id, bool admin) { using (FilmDataContext ctx = new FilmDataContext()) { DataObject.EF.User user = ctx.Users.Where(u => u.UserID == id).FirstOrDefault(); if (user != null) { user.isAdmin = admin; return(ctx.SaveChanges()); } else { return(0); } } }