Пример #1
0
        public List <SpecialistTag> SpecialistTag(int id)
        {
            SqlConnection con = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            List <SpecialistTag> lista = new List <SpecialistTag>();

            try
            {
                TagManager tagmanager = new TagManager();

                string     sql = "Select Id,TagId,specialistid from SpecialistTags where specialistid = @specialistid";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@specialistid", System.Data.SqlDbType.NVarChar).Value = id;
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    SpecialistTag spe = new SpecialistTag();
                    spe.id            = reader.GetInt32(0);
                    spe.tag           = tagmanager.Obtener(reader.GetInt32(1));
                    spe.specialist.id = reader.GetInt32(2);
                    lista.Add(spe);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(lista);
        }
Пример #2
0
        public SpecialistTag SpecialistTagUnique(int id)
        {
            TagManager    tagmanager = new TagManager();
            SpecialistTag spe        = null;
            SqlConnection con        = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            string     sql = "Select Id,TagId,specialistid from SpecialistTags where Id = @idSpectags";
            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.Parameters.Add("@idSpectags", System.Data.SqlDbType.NVarChar).Value = id;
            SqlDataReader reader =
                cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            if (reader.Read())
            {
                spe               = new SpecialistTag();
                spe.id            = reader.GetInt32(0);
                spe.tag           = tagmanager.Obtener(reader.GetInt32(1));
                spe.specialist.id = reader.GetInt32(2);
            }
            reader.Close();
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(spe);
        }
Пример #3
0
 public IHttpActionResult PutSpecTag(int id, int spectagid, [FromBody] SpecialistTag esp)
 {
     try{
         SpecialistTagManager manager = new SpecialistTagManager();
         SpecialistTag        temp    = manager.Obtener(spectagid);
         if (temp.tag.id == id)
         {
             SpecialistTag result = manager.Editar(spectagid, temp.tag.id);
             if (result != null)
             {
                 return(Ok());
             }
             else
             {
                 return(BadRequest());
             }
         }
         else
         {
             return(NotFound());
         }
     }catch (Exception e) {
         return(NotFound());
     }
 }
Пример #4
0
        public SpecialistTag Insertar(SpecialistTag spe)
        {
            SpecialistTag result = null;
            SqlConnection con    = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            try
            {
                string sql = "Insert into SpecialistTags(TagId,specialistid) output INSERTED.Id values(@tgd,@specialist)";

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@tgd", System.Data.SqlDbType.Int).Value        = spe.tag.id;
                cmd.Parameters.Add("@specialist", System.Data.SqlDbType.Int).Value = spe.specialist.id;
                int modified = (int)cmd.ExecuteScalar();
                if (modified != 0)
                {
                    TagManager tagManager = new TagManager();
                    result     = Obtener(modified);
                    result.tag = tagManager.Obtener(result.tag.id);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = null;
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(result);
        }
Пример #5
0
        public SpecialistTag Editar(int id, int tagid)
        {
            SpecialistTag result = null;
            SqlConnection con    = new SqlConnection(Resource.CadenaConexion);

            con.Open();
            try
            {
                string     sql = "Update SpecialistTags set TagId = @tgd output INSERTED.Id where Id = @id";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@tgd", System.Data.SqlDbType.Int).Value = tagid;
                cmd.Parameters.Add("@id", System.Data.SqlDbType.Int).Value  = id;
                int modified = (int)cmd.ExecuteScalar();
                if (modified != 0)
                {
                    result = Obtener(modified);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = null;
            }
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            return(result);
        }
Пример #6
0
 public IHttpActionResult PostSpecTag(int id, [FromBody] SpecialistTag specialisttag)
 {
     try{
         SpecialistTagManager manager = new SpecialistTagManager();
         specialisttag.tag.id = id;
         SpecialistTag result = manager.Insertar(specialisttag);
         if (result != null)
         {
             return(Created(new Uri(Url.Link(ViewRouteName, new { id = result.tag.id })), result));
         }
         else
         {
             return(BadRequest());
         }
     }catch (Exception e) {
         return(NotFound());
     }
 }
Пример #7
0
 public IHttpActionResult GetUniqueSpecTag(int id, int specialisttagid)
 {
     try
     {
         SpecialistManager manager       = new SpecialistManager();
         SpecialistTag     specialisttag = manager.SpecialistTagUnique(specialisttagid);
         if (specialisttag.specialist.id == id)
         {
             return(Ok(specialisttag));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception e)
     {
         return(NotFound());
     }
 }