Ejemplo n.º 1
0
        // POST api/values
        public int Post(memberget value)
        {
            var connection = new SqlConnection(connectionString);

            connection.Open();
            var sqlCommand = new SqlCommand($"insert into members (name,position,tag) values ('{value.lastname}','{value.position}','{value.tag}'); select scope_identity()", connection);
            var createdid  = sqlCommand.ExecuteScalar();

            sqlCommand.CommandText = $"insert into contacts (mail,skype,memberID) values ('{value.mail}','{value.skype}',{Convert.ToInt32(createdid)})";
            sqlCommand.ExecuteNonQuery();
            connection.Close();
            return(Convert.ToInt32(createdid));
        }
Ejemplo n.º 2
0
        // PUT api/values/5
        public int Put(int id, memberget value)
        {
            var connection = new SqlConnection(connectionString);

            connection.Open();

            var oldMember = getmemberbyid(id);

            var elemforuploads = new member();
            var elemforcont    = new contacts();

            elemforuploads.ID = oldMember.ID;
            if (string.IsNullOrEmpty(value.lastname))
            {
                elemforuploads.name = oldMember.name;
            }
            else
            {
                elemforuploads.name = value.lastname;
            }
            if (string.IsNullOrEmpty(value.tag))
            {
                elemforuploads.tag = oldMember.tag;
            }
            else
            {
                elemforuploads.tag = value.tag;
            }

            if (string.IsNullOrEmpty(value.position))
            {
                elemforuploads.position = oldMember.position;
            }
            else
            {
                elemforuploads.position = value.position;
            }
            elemforuploads.contacts = elemforcont;

            if (string.IsNullOrEmpty(value.mail))
            {
                elemforcont.mail = oldMember.contacts.mail;
            }
            else
            {
                elemforcont.mail = value.mail;
            }

            if (string.IsNullOrEmpty(value.skype))
            {
                elemforcont.skype = oldMember.contacts.skype;
            }
            else
            {
                elemforcont.skype = value.skype;
            }
            var sqlcommand = new SqlCommand($"update members set name = '{elemforuploads.name}', position = '{elemforuploads.position}', tag = '{elemforuploads.tag}' where ID = {elemforuploads.ID}", connection);

            sqlcommand.ExecuteNonQuery();
            sqlcommand.CommandText = $"update contacts set mail = '{elemforcont.mail}', skype = '{elemforcont.skype}' where memberID = {id}";
            sqlcommand.ExecuteNonQuery();
            connection.Close();
            return(elemforuploads.ID);
        }