Beispiel #1
0
        public string Crear(DataServicio Data)
        {
            string authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];

            if (HToken.check(authHeader))
            {
                if (Data.Id != 0)
                {
                    CustomErrorDetail customError = new CustomErrorDetail(400, "Error en la peticion", "La peticion no tiene el formato requerido");
                    throw new WebFaultException <CustomErrorDetail>(customError, HttpStatusCode.BadRequest);
                }

                return(JsonConvert.SerializeObject(new { Respuesta = _sv.CrearServicio(Data) }));
            }

            WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authorization: Token realm=\"wscreate\"");
            throw new WebFaultException(HttpStatusCode.Unauthorized);
        }
Beispiel #2
0
        public string Actualizar(DataServicio Data)
        {
            string authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];

            if (HToken.check(authHeader))
            {
                if (Data.Id == 0)
                {
                    CustomErrorDetail customError = new CustomErrorDetail(404, "Dato Faltante", "El identificador no se encontro");
                    throw new WebFaultException <CustomErrorDetail>(customError, HttpStatusCode.NotFound);
                }

                return(JsonConvert.SerializeObject(new { Respuesta = _sv.ActualizarServicio(Data) }));
            }

            WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authorization: Token realm=\"wsupdate\"");
            throw new WebFaultException(HttpStatusCode.Unauthorized);
        }
Beispiel #3
0
        public string UploadImg(UploadImgB File)
        {
            string authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];

            if (HToken.check(authHeader))
            {
                if (string.IsNullOrEmpty(File.Nombre) && string.IsNullOrEmpty(File.Imagen))
                {
                    CustomErrorDetail customError = new CustomErrorDetail(404, "Dato Faltante", "El nombre y la imagen son obligatorios");
                    throw new WebFaultException <CustomErrorDetail>(customError, HttpStatusCode.NotFound);
                }

                HUploadImgeBit.ImagesSys(File.Imagen, File.Nombre, "/Recursos/");
                return(JsonConvert.SerializeObject(new { Respuesta = _me.UploadImgBit(File) }));
            }

            WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authorization: Token realm=\"wsuploadbit\"");
            throw new WebFaultException(HttpStatusCode.Unauthorized);
        }
Beispiel #4
0
        public string MostrarRegistro(string Id)
        {
            string authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];
            int    valorId    = Convert.ToInt32(Id);

            if (HToken.check(authHeader))
            {
                if (!string.IsNullOrEmpty(Id))
                {
                    CustomErrorDetail customError = new CustomErrorDetail(404, "Dato Faltante", "El identificador no se encontro");
                    throw new WebFaultException <CustomErrorDetail>(customError, HttpStatusCode.NotFound);
                }

                return(JsonConvert.SerializeObject(new { Respuesta = _sv.MuestraServicio(valorId) }));
            }

            WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authorization: Token realm=\"wsread\"");
            throw new WebFaultException(HttpStatusCode.Unauthorized);
        }