Пример #1
0
        public HttpResponseMessage Post(StEmpresas model)
        {
            var mierror = "";

            try
            {
                var response = Request.CreateResponse(HttpStatusCode.OK);
                if (string.IsNullOrEmpty(model.Id))
                {
                    return(CrearListado(response, model));
                }
                else
                {
                    return(CrearEmpresa(response, model));
                }
            }
            catch (Exception ex)
            {
                mierror = ex.Message;
            }

            var responseError = Request.CreateResponse(HttpStatusCode.InternalServerError);

            responseError.Content = new StringContent(mierror, Encoding.UTF8, "application/json");
            return(responseError);
        }
Пример #2
0
        private HttpResponseMessage CrearEmpresa(HttpResponseMessage input, StEmpresas model)
        {
            using (var service = FService.Instance.GetService(typeof(EmpresaModel), ContextService, MarfilEntities.ConnectToSqlServer(model.Basedatos)) as EmpresasService)
            {
                var list = service.get(model.Id);

                input.Content = new StringContent(JsonConvert.SerializeObject(list), Encoding.UTF8,
                                                  "application/json");
                return(input);
            }
        }
Пример #3
0
        private HttpResponseMessage CrearListado(HttpResponseMessage input, StEmpresas model)
        {
            using (
                var service = FService.Instance.GetService(typeof(EmpresaModel), ContextService, MarfilEntities.ConnectToSqlServer(model.Basedatos)) as EmpresasService)
            {
                var list = service.GetAll <EmpresaModel>();

                var result = new ResultBusquedas <EmpresaModel>()
                {
                    values  = list,
                    columns = new[]
                    {
                        new ColumnDefinition()
                        {
                            field       = "Id",
                            displayName = "Id",
                            visible     = true,
                            filter      = new Filter()
                            {
                                condition = ColumnDefinition.STARTS_WITH
                            }
                        },
                        new ColumnDefinition()
                        {
                            field       = "Nombre",
                            displayName = "Nombre",
                            visible     = true,
                            filter      = new Filter()
                            {
                                condition = ColumnDefinition.STARTS_WITH
                            }
                        },
                    }
                };


                input.Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8,
                                                  "application/json");
                return(input);
            }
        }