public void AddUser(User user) { Console.WriteLine("Dato: " + user.DateOfBirth); var userDto = new UserDto { DateOfBirth = user.DateOfBirth, Email = user.Email, Name = user.Name, Gender = user.Gender }; _resultDataService.AddUser(userDto); }
public ICollection<UserDto> GetAllUsers() { const string userTemplate = "Northernrunners.ImportLibrary.Resources.GetAllUsersTemplate.txt"; using (var stream = _assembly.GetManifestResourceStream(userTemplate)) { var stopwatch = new Stopwatch(); stopwatch.Start(); var sql = Tools.StreamToString(stream); var query = new Query { Sql = sql }; var result = _sqlDirectService.RunCommand(query); var returnList = new List<UserDto>(); foreach (var d in result) { DateTime dateOfBirth = DateTime.MinValue; if (!string.IsNullOrEmpty(Convert.ToString(d["dob"]))) { dateOfBirth = Tools.ParseDate(Convert.ToString(d["dob"])); } var x2 = new UserDto { DateOfBirth = dateOfBirth, Gender = Convert.ToString(d["gender"]), Email = Convert.ToString(d["email"]), Name = Convert.ToString(d["name"]), Id = Convert.ToInt32(d["id"]) }; returnList.Add(x2); stopwatch.Stop(); } return returnList; } }
public void UpdateUser(UserDto user) { var sql = "delete from wp_usermeta where user_id = @id and meta_key like 'wp-athletics%'"; var query = new Query {Sql = sql}; query.ParameterValues.Add(new Parameter("@id", user.Id)); _sqlDirectService.RunCommand(query); sql = "INSERT INTO `wp_usermeta` VALUES (null, @userid,'wp-athletics_dob',@dob),(null, @userid,'wp-athletics_gender',@gender), (null,@userid, 'wp-athletics_hide_dob', 'yes')"; query = new Query {Sql = sql}; query.ParameterValues.Add(new Parameter("@userid", user.Id)); query.ParameterValues.Add(new Parameter("@dob", Tools.ParseDate(user.DateOfBirth))); query.ParameterValues.Add(new Parameter("@gender", user.Gender)); _sqlDirectService.RunCommand(query); }
public void AddUser(UserDto user) { //if (user.DateOfBirth.Equals(DateTime.MinValue)) //{ // user.DateOfBirth = Tools.Randomize(new Random()); //} var userTemplate = "Northernrunners.ImportLibrary.Resources.CreateUserTemplate.txt"; var queries = new List<Query>(); Query query; var email = user.Email ?? ""; using (var stream = _assembly.GetManifestResourceStream(userTemplate)) { var sql = Tools.StreamToString(stream); query = new Query { Sql = sql }; } var username = user.Name.Replace(" ", string.Empty); query.ParameterValues.Add(new Parameter("@username", username)); query.ParameterValues.Add(new Parameter("@email", email)); query.ParameterValues.Add(new Parameter("@date", user.DateOfBirth)); query.ParameterValues.Add(new Parameter("@fullname", user.Name)); queries.Add(query); query = new Query { Sql = "select id from wp_users where user_login = @username" }; query.ParameterValues.Add(new Parameter("username", username)); queries.Add(query); var result = _sqlDirectService.RunCommandsInSingleTransaction(queries); var dataset = result.ToList()[1]; var dictionary = dataset.ToList()[0]; var userId = Convert.ToInt32(dictionary["id"]); userTemplate = "Northernrunners.ImportLibrary.Resources.CreateUsermetaTemplate.txt"; using (var stream = _assembly.GetManifestResourceStream(userTemplate)) { var sql = Tools.StreamToString(stream); query = new Query { Sql = sql }; } var split = user.Name.Split(' '); var size = split.Length; var lastname = split[size - 1]; var firstname = user.Name.Replace(lastname, string.Empty); var gender = user.Gender; query.ParameterValues.Add(new Parameter("@userid", userId)); query.ParameterValues.Add(new Parameter("@username", username)); query.ParameterValues.Add(new Parameter("@firstname", firstname)); query.ParameterValues.Add(new Parameter("@lastname", lastname)); query.ParameterValues.Add(new Parameter("@dob", Tools.ParseDate(user.DateOfBirth))); query.ParameterValues.Add(new Parameter("@gender", gender)); _sqlDirectService.RunCommand(query); }
public void UpdateUser(User user) { var userDto = new UserDto { DateOfBirth = user.DateOfBirth, Email = user.Email, Gender = user.Gender, Id = user.Id }; userDto.Name = userDto.Name; _resultDataService.UpdateUser(userDto); }