Exemplo n.º 1
0
 public ActionResult _AddPersonalAttribute(Model.AddPersonalAttributeModel pModel)
 {
     if (ModelState.IsValid)
     {
         AttributeTypeDTO     attributesTypes = categorieProvider.getAttributeType(pModel.id_typePA).Result;
         Regex                r = new Regex(attributesTypes.reg_expr);
         PersonalAttributeDTO personaAttributeDTO = new PersonalAttributeDTO();
         if (attributesTypes.reg_expr == "" || r.Match(pModel.valuePA).Success)
         {
             personaAttributeDTO.name         = pModel.attributePA;
             personaAttributeDTO.value        = pModel.valuePA;
             personaAttributeDTO.type_id      = pModel.id_typePA;
             personaAttributeDTO.userLog      = Request.Cookies["user_id"].Value;
             personaAttributeDTO.createdBy    = personaAttributeDTO.userLog;
             personaAttributeDTO.categorie_id = pModel.categorie_idPA;
             if (categorieProvider.postPersonalAttribute(personaAttributeDTO).Result)
             {
                 return(_PersonalAttrList(pModel.categorie_idPA));
             }
         }
         else
         {
             return(new HttpStatusCodeResult(404, "El campo valor es inválido"));
         }
     }
     return(new HttpStatusCodeResult(404, "Error, no se puede agregar el atributo"));
 }
Exemplo n.º 2
0
 public ActionResult _EditPersonalAttribute(Model.EditPersonalAttributeModel pModel)
 {
     if (ModelState.IsValid)
     {
         AttributeTypeDTO     attributesType = categorieProvider.getAttributeType(pModel.id_type).Result;
         Regex                r = new Regex(attributesType.reg_expr);
         PersonalAttributeDTO personalAttributeDTO = new PersonalAttributeDTO();
         if (attributesType.reg_expr == "" || r.Match(pModel.value).Success)
         {
             personalAttributeDTO.name         = pModel.attribute;
             personalAttributeDTO.value        = pModel.value;
             personalAttributeDTO.type_id      = pModel.id_type;
             personalAttributeDTO.isEnabled    = pModel.isEnabled == "on" ? "true" : "false";
             personalAttributeDTO.userLog      = Request.Cookies["user_id"].Value;
             personalAttributeDTO.id_attribute = pModel.id_attribute;
             if (categorieProvider.putPersonalAttribute(personalAttributeDTO).Result)
             {
                 return(new HttpStatusCodeResult(200, "El atributo se ha editado con éxito"));
             }
         }
         else
         {
             return(new HttpStatusCodeResult(404, "El campo valor es inválido"));
         }
     }
     else
     {
         return(new HttpStatusCodeResult(404, "Error, debe completar todos los campos"));
     }
     return(new HttpStatusCodeResult(404, "Error, no se puede agregar el atributo"));
 }
        public static bool updatePersonalAttribute(PersonalAttributeDTO pGeneralAttributeDTO)
        {
            using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionRRHHDatabase"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("usp_update_personalAttribute", connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                command.Parameters.Add("@id_attribute", SqlDbType.Int);
                command.Parameters["@id_attribute"].Value = pGeneralAttributeDTO.id_attribute;
                command.Parameters.Add("@name", SqlDbType.NVarChar);
                command.Parameters["@name"].Value = pGeneralAttributeDTO.name;
                command.Parameters.Add("@type_id", SqlDbType.Int);
                command.Parameters["@type_id"].Value = pGeneralAttributeDTO.type_id;
                command.Parameters.Add("@value", SqlDbType.NVarChar);
                command.Parameters["@value"].Value = pGeneralAttributeDTO.value;
                command.Parameters.Add("@isEnabled", SqlDbType.Bit);
                command.Parameters["@isEnabled"].Value = pGeneralAttributeDTO.isEnabled;
                command.Parameters.Add("@userLog", SqlDbType.Int);
                command.Parameters["@userLog"].Value = pGeneralAttributeDTO.userLog;

                command.Connection.Open();
                int result = command.ExecuteNonQuery();
                if (result != 0)
                {
                    return(true);
                }
                return(false);
            };
        }
        public static PersonalAttributeDTO getPersonalAttribute(string id_attribute)
        {
            PersonalAttributeDTO personalAttributeDTO = new PersonalAttributeDTO();

            using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionRRHHDatabase"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("usp_get_personalAttribute", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@id_attribute", SqlDbType.Int);
                command.Parameters["@id_attribute"].Value = id_attribute;
                command.Connection.Open();
                SqlDataReader rdr = command.ExecuteReader();
                while (rdr.Read())
                {
                    personalAttributeDTO.id_attribute = rdr["id_attribute"].ToString();
                    personalAttributeDTO.categorie_id = rdr["categorie_id"].ToString();
                    personalAttributeDTO.name         = rdr["name"].ToString();
                    personalAttributeDTO.type_id      = rdr["type"].ToString();
                    personalAttributeDTO.value        = rdr["value"].ToString();
                    personalAttributeDTO.isEnabled    = rdr["isEnabled"].ToString();
                    personalAttributeDTO.createdBy    = rdr["createdBy"].ToString();
                    personalAttributeDTO.createdDate  = rdr["createdDate"].ToString();
                }
            };
            return(personalAttributeDTO);
        }
 public IHttpActionResult putPersonalAtrribute(PersonalAttributeDTO pPersonaAttributeDTO)
 {
     if (!CategoriesData.updatePersonalAttribute(pPersonaAttributeDTO))
     {
         return(BadRequest());
     }
     return(Ok());
 }
Exemplo n.º 6
0
        public ActionResult _DeletePersonalAttribute(string id_attribute)
        {
            PersonalAttributeDTO personalAttributeDTO = new PersonalAttributeDTO();

            personalAttributeDTO.id_attribute = id_attribute;
            personalAttributeDTO.userLog      = Request.Cookies["user_id"].Value;;
            if (categorieProvider.deletePersonalAttribute(personalAttributeDTO).Result)
            {
                return(new HttpStatusCodeResult(200));
            }
            return(new HttpStatusCodeResult(404, "Error, el atributo no se puede eliminar"));
        }
 public async Task <bool> deletePersonalAttribute(PersonalAttributeDTO pPersonalAttributeDTO)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri(_BaseAddress);
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", getToken());
         HttpResponseMessage response = client.DeleteAsync("api/categories/personalAttr/?id_attribute=" + pPersonalAttributeDTO.id_attribute + "&userLog=" + pPersonalAttributeDTO.userLog).Result;
         if (response.IsSuccessStatusCode)
         {
             return(true);
         }
         return(false);
     }
 }
 public async Task <bool> putPersonalAttribute(PersonalAttributeDTO pPersonalAttributeDTO)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri(_BaseAddress);
         var         userJson    = new JavaScriptSerializer().Serialize(pPersonalAttributeDTO);
         HttpContent contentPost = new StringContent(userJson, Encoding.UTF8, "application/json");
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", getToken());
         HttpResponseMessage response = client.PutAsync("api/categories/personalAttr", contentPost).Result;
         if (response.IsSuccessStatusCode)
         {
             return(true);
         }
         return(false);
     }
 }
        public async Task <PersonalAttributeDTO> getPersonalAttribute(string id_attribute)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_BaseAddress);
                PersonalAttributeDTO personalAttributeDTO = new PersonalAttributeDTO();
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", getToken());
                HttpResponseMessage response = client.GetAsync("api/categories/personalAttr/?id_attribute=" + id_attribute).Result;
                if (response.IsSuccessStatusCode)
                {
                    string result = await response.Content.ReadAsStringAsync();

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    personalAttributeDTO = serializer.Deserialize <PersonalAttributeDTO>(result);
                }
                return(personalAttributeDTO);
            }
        }
        public PersonalAttributeDTO getPersonalAttribute(string id_attribute)
        {
            PersonalAttributeDTO attribute = CategoriesData.getPersonalAttribute(id_attribute);

            return(attribute);
        }