Exemplo n.º 1
0
        public static int Grabar(Models.Categorias categ, int EsNuevo)
        {
            try
            {
                if (categ != null)
                {
                    ApiServices         objApi   = new ApiServices();
                    HttpResponseMessage response = null;
                    string Request = Newtonsoft.Json.JsonConvert.SerializeObject(categ);
                    if (EsNuevo == 0)
                    {
                        response = objApi.CallService("categorias/" + categ.Id, Request, ApiServices.TypeMethods.PUT).Result;
                    }
                    else
                    {
                        response = objApi.CallService("categorias", Request, ApiServices.TypeMethods.POST).Result;
                    }

                    if (response.IsSuccessStatusCode)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(0);
            }
        }
Exemplo n.º 2
0
        public static List <Models.Categorias> IniModalEdit(string Id)
        {
            List <Models.Categorias> lista = new List <Models.Categorias>();

            try
            {
                if (Id != "0")
                {
                    Int64               IdCateg  = Convert.ToInt64(Id);
                    ApiServices         objApi   = new ApiServices();
                    string              Request  = "{}";
                    HttpResponseMessage response = objApi.CallService("categorias/" + IdCateg, Request, ApiServices.TypeMethods.GET).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        //resp = await response.Content.ReadAsAsync();
                        string            Respuesta = response.Content.ReadAsStringAsync().Result;
                        Models.Categorias obj       = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.Categorias>(Respuesta);
                        if (obj != null)
                        {
                            lista.Add(new Models.Categorias
                            {
                                Id     = obj.Id,
                                Nombre = obj.Nombre,
                                Imagen = obj.Imagen,
                                Logo   = obj.Logo
                            });
                        }
                    }
                }
            }
            catch
            {
                int sss = 0;
            }
            return(lista);
        }