Ejemplo n.º 1
0
 private void save(Models.User User, bool isUpdate = false)
 {
     if (!isUpdate)
     {
         this.context.Users.Add(User);
     }
     this.context.SaveChanges();
 }
Ejemplo n.º 2
0
 public void MapToUserRepo(Models.User user)
 {
     this.User = new UserRepository()
     {
         Id   = user.Id,
         Name = user.Name
     };
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 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();
 }