public PersonModel Create(Person person) { return new PersonModel { Url = _urlHelper.Link("PersonApi", new { id = person.Id }), Name = person.Name, Gender = person.Gender }; }
/// <summary> /// Add a new person to the database /// </summary> /// <param name="person"></param> public void Add(Person person) { person.Id = GetNewId(); using (var connection = new MySqlConnection( "server=localhost;database=imdb;uid=bulskov;pwd=henrik")) { connection.Open(); var cmd = new MySqlCommand( "insert into name(id,name,gender) values(@id, @name, @gender)", connection); cmd.Parameters.AddWithValue("@id", person.Id); cmd.Parameters.AddWithValue("@name", person.Name); cmd.Parameters.AddWithValue("@gender", person.Gender); cmd.ExecuteNonQuery(); } }
/// <summary> /// Update a person in the database /// </summary> /// <param name="person"></param> public void Update(Person person) { using (var connection = new MySqlConnection( "server=localhost;database=imdb;uid=bulskov;pwd=henrik")) { connection.Open(); var cmd = new MySqlCommand( "update name set name = @name, gender = @gender where id = @id", connection); cmd.Parameters.AddWithValue("@id", person.Id); cmd.Parameters.AddWithValue("@name", person.Name); cmd.Parameters.AddWithValue("@gender", person.Gender); cmd.ExecuteNonQuery(); } }