コード例 #1
0
 public PersonModel Create(Person person)
 {
     return new PersonModel
     {
         Url = _urlHelper.Link("PersonApi", new { id = person.Id }),
         Name = person.Name,
         Gender = person.Gender
     };
 }
コード例 #2
0
        /// <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();
            }
        }
コード例 #3
0
        /// <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();
            }
        }