private void save(Models.User User, bool isUpdate = false) { if (!isUpdate) { this.context.Users.Add(User); } this.context.SaveChanges(); }
public void MapToUserRepo(Models.User user) { this.User = new UserRepository() { Id = user.Id, Name = user.Name }; }
public void Create(UserRepository userRepository) { Models.User newUser = new Models.User(); newUser.Name = userRepository.Name; newUser.Email = userRepository.Email; newUser.Password = userRepository.Password; this.save(newUser); }
public void Update(long id, UserRepository userRepository) { Models.User oldUser = this.userQueryRepository.Find(id); if (oldUser == null) { return; } oldUser.Name = userRepository.Name; this.save(oldUser, true); }
public UserRepository FindById(long id = 0) { Models.User user = this.Find(id); if (user == null) { return(new UserRepository()); } this.userRepository.Id = user.Id; this.userRepository.Name = user.Name; return(this.userRepository); }
public UserRepository FindByEmail(string email = "") { Models.User user = this.context.Users.Where(user => user.Email == email).FirstOrDefault(); if (user == null) { return(new UserRepository()); } this.userRepository.Id = user.Id; this.userRepository.Name = user.Name; this.userRepository.Email = user.Email; this.userRepository.Password = user.Password; return(this.userRepository); }
public UserRepository FindQueryWhere(string column, string data) { string query = $"SELECT * FROM users WHERE {column} = '{data}'"; Models.User user = this.context.Users.FromSqlRaw(query).FirstOrDefault(); if (user == null) { return(new UserRepository()); } this.userRepository.Id = user.Id; this.userRepository.Name = user.Name; this.userRepository.Email = user.Email; this.userRepository.Password = user.Password; return(this.userRepository); }
public void Delete(long id) { Models.User user = this.context.Users.Where(user => user.Id == id).FirstOrDefault(); this.context.Users.Remove(user); this.context.SaveChanges(); }