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

            if (HToken.check(authHeader))
            {
                return(JsonConvert.SerializeObject(new { Respuesta = _sv.MuestraServicios() }));
            }

            WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authorization: Token realm=\"wsread\"");
            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 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 #4
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 #5
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);
        }
Beispiel #6
0
        public ResponseAPI Execute(HttpContext context, dynamic dataReq = null)
        {
            ResponseAPI res = new ResponseAPI();

            StringValues HToken;

            context.Request.Headers.TryGetValue("Token", out HToken);
            Token = HToken.ToString();

            DateTime StartTime     = DateTime.Now;
            string   StackTraceMsg = string.Empty;

            try
            {
                StringValues HAccessToken;
                context.Request.Headers.TryGetValue("AccessToken", out HAccessToken);
                AccessToken = HAccessToken.ToString();

                IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress = /*string.Join(',', heserver.AddressList.Select(x => x.ToString()).ToList());*/ context.Connection.RemoteIpAddress.ToString();

                StringValues HUserAgent;
                context.Request.Headers.TryGetValue("User-Agent", out HUserAgent);
                UserAgent = HUserAgent.ToString();

                StringValues HRecaptchaResponse;
                context.Request.Headers.TryGetValue("RecaptchaResponse", out HRecaptchaResponse);
                RecaptchaResponse = HRecaptchaResponse.ToString();

                // if (!this.GetType().Name.Equals("OauthAccessTokenGet")) this.ValidatePermission();

                /*
                 *   StringValues Husercode;
                 *   context.Request.Headers.TryGetValue("UserCode", out Husercode);
                 *   UserCode = Husercode.ToString();
                 */

                if (dataReq != null)
                {
                    try
                    {
                        dataReq = this.MappingRequest(dataReq);
                    }
                    catch (Exception)
                    {
                        dataReq = this.MappingRequestArr(dataReq);
                    }
                }

                this.ExecuteChild(dataReq, res);

                res.code    = "S0001";
                res.message = "SUCCESS";
                res.status  = "S";
            }
            catch (Exception ex)
            {
                StackTraceMsg = ex.StackTrace;
                //map error code, message
                ErrorCode error = EnumUtil.GetEnum <ErrorCode>(ex.Message);
                res.code = error.ToString();
                if (res.code == ErrorCode.U000.ToString())
                {
                    res.message = ex.Message;
                }
                else
                {
                    res.message = error.GetDescription();
                }

                res.status = "F";
            }
            finally
            {
                ASSETKKF_ADO.Mssql.Mcis.muAPILogAdo.GetInstant().Insert(new ASSETKKF_MODEL.Data.Mssql.Mcis.muAPILog()
                {
                    Token   = Token,
                    APIName = this.GetType().Name,
                    //RefID = this.Logger.RefID,
                    ServerName    = Environment.MachineName,
                    StartDate     = StartTime,
                    EndDate       = DateTime.Now,
                    Status        = res.status,
                    StatusMessage = res.message,
                    Input         = this.GetType().Name.Equals("OauthLogin") ? "" : JsonConvert.SerializeObject(dataReq),
                    Output        = JsonConvert.SerializeObject(res),
                    Remark        = StackTraceMsg
                });
            }
            return(res);
        }