Ejemplo n.º 1
0
        }//Edit a user by a specified from the DTO ID

        public UserDTO Get(int id)
        {
            ATPEntities _dbContext = new ATPEntities(); //Database context(database connection)
            //Get User if there exists one with the specified username and convert to DTO
            USER_NEW_NEW userEntity = _dbContext.USER_NEW_NEW.FirstOrDefault(user => user.ID == id);

            return(Convert(userEntity));
        }//Get a user by a specified ID
Ejemplo n.º 2
0
        }//Get all users

        #region Mappers

        private UserDTO Convert(USER_NEW_NEW userEntity) => new UserDTO
        {
            Username       = userEntity.USERNAME,
            Password       = userEntity.PASSWORD,
            About          = userEntity.ABOUT,
            Email          = userEntity.EMAIL,
            Gender         = userEntity.GENDER,
            SecretAnswer   = userEntity.SECRET_A,
            SecretQuestion = userEntity.SECRET_Q,
            ID             = userEntity.ID
        };
Ejemplo n.º 3
0
        }//Delete a user by a specified ID

        public void Edit(UserDTO dto)
        {
            ATPEntities  _dbContext = new ATPEntities(); //Database context(database connection)
            USER_NEW_NEW userOld    = _dbContext.USER_NEW_NEW.FirstOrDefault(user => user.USERNAME == dto.Username);
            USER_NEW_NEW userNew    = Convert(dto);

            //Map values from new entity to the existing version because this is how it must be done
            foreach (PropertyInfo property in userOld.GetType().GetProperties())
            {
                property.SetValue(userOld, property.GetValue(userNew));
            }
            _dbContext.SaveChanges();//ALWAYS SAVE AFTER BEING DONE. Make only one transfer to the database for safety reasons
        }//Edit a user by a specified from the DTO ID