Esempio n. 1
0
        public string HttpPost(string method, Object request)
        {
            try
            {
                string uri        = ConfigurationManager.AppSettings["urlApi"];
                string user       = ConfigurationManager.AppSettings["usr"];
                string pwd        = ConfigurationManager.AppSettings["pwd"];
                string json       = JsonConvert.SerializeObject(request);
                string HtmlResult = "";

                // Completar la url agregandole el método
                uri += method;

                using (WebClient wc = new WebClient())
                {
                    wc.Encoding = Encoding.UTF8;
                    wc.Headers[HttpRequestHeader.ContentType]     = "application/json;charset=UTF-8";
                    wc.Headers[HttpRequestHeader.ContentEncoding] = "UTF-8";
                    wc.Headers[HttpRequestHeader.Authorization]   = "Basic " + LogicCommon.encondeBase64(user + ":" + pwd);

                    // Pasar a encoding UTF-8 el json
                    byte[] bytes = Encoding.UTF8.GetBytes(json);
                    json = Encoding.UTF8.GetString(bytes);

                    HtmlResult = wc.UploadString(uri, json);
                }

                return(HtmlResult);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
        public ResponseAdminWareHouseList getWareHouseList(RequestAdminWareHouse req)
        {
            ResponseAdminWareHouseList response = new ResponseAdminWareHouseList();

            try
            {
                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("WareHouse/getAdminWareHouse", req);
                response = JsonConvert.DeserializeObject <ResponseAdminWareHouseList>(json);

                // Obtener el listado de sedes
                RequestAdminCompany      reqCompany    = new RequestAdminCompany();
                ResponseAdminCompanyList resCompany    = new ResponseAdminCompanyList();
                LogicAdminCompany        logicCompany  = new LogicAdminCompany();
                List <SelectListItem>    lstTmpCompany = new List <SelectListItem>();

                // Obtener el listado completo de sedes
                reqCompany.id = 0;
                resCompany    = logicCompany.getCompanyList(reqCompany);

                // Llenar el listado de sedes
                foreach (ResponseAdminCompanyDetail r in resCompany.lst)
                {
                    lstTmpCompany.Add(new SelectListItem
                    {
                        Text     = r.name,
                        Value    = r.id.ToString(),
                        Selected = r.id == req.idCompany ? true : false
                    });
                }

                // Agregar el listado de sede
                response.lstCompany = lstTmpCompany;


                return(response);
            }
            catch (Exception ex)
            {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }
Esempio n. 3
0
        public string HttpGet(string method, string[] parameters = null)
        {
            try
            {
                string uri        = ConfigurationManager.AppSettings["urlApi"];
                string user       = ConfigurationManager.AppSettings["usr"];
                string pwd        = ConfigurationManager.AppSettings["pwd"];
                string HtmlResult = "";
                int    first      = 0;

                // Completar la url agregandole el método
                uri += method;

                // Completar la url agregandole los parámetros
                if (parameters != null)
                {
                    foreach (string p in parameters)
                    {
                        if (first == 0)
                        {
                            uri += "?" + p;
                        }
                        else
                        {
                            uri += "&" + p;
                        }
                    }
                }

                using (WebClient wc = new WebClient())
                {
                    wc.Headers[HttpRequestHeader.ContentType]     = "application/json;charset=utf-8";
                    wc.Headers[HttpRequestHeader.ContentEncoding] = "UTF-8";
                    wc.Headers[HttpRequestHeader.Authorization]   = "Basic " + LogicCommon.encondeBase64(user + ":" + pwd);

                    HtmlResult = wc.DownloadString(uri);
                }

                return(HtmlResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ValidateUserResponse validateUser(ValidateUserRequest request)
        {
            ValidateUserResponse response = new ValidateUserResponse();

            try
            {
                LogicCommon com    = new LogicCommon();
                string      result = "";
                result   = com.HttpPost("user/validate", request);
                response = JsonConvert.DeserializeObject <ValidateUserResponse>(result);
            }
            catch (Exception ex) {
                response.code    = -1;
                response.message = "Ocurrio un error inesperado, favor avisar al administrador.";
            }

            return(response);
        }
Esempio n. 5
0
        public ResponseAdminRoleList getRoleList(RequestAdminRole req)
        {
            ResponseAdminRoleList response = new ResponseAdminRoleList();

            try
            {
                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("Role/getAdminRole", req);
                response = JsonConvert.DeserializeObject <ResponseAdminRoleList>(json);

                return(response);
            }
            catch (Exception ex) {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }
Esempio n. 6
0
        public ResponseAdminClsMaster setClsMaster(RequestAdminClsMaster req)
        {
            ResponseAdminClsMaster response = new ResponseAdminClsMaster();

            try
            {
                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("ClsMaster/adminClsMaster", req);
                response = JsonConvert.DeserializeObject <ResponseAdminClsMaster>(json);

                return(response);
            }
            catch (Exception ex)
            {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }
Esempio n. 7
0
        public ResponseAdminGlobalParam setGlobalParam(RequestAdminGlobalParam req)
        {
            ResponseAdminGlobalParam response = new ResponseAdminGlobalParam();

            try
            {
                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("GlobalParam/adminGlobalParam", req);
                response = JsonConvert.DeserializeObject <ResponseAdminGlobalParam>(json);

                return(response);
            }
            catch (Exception ex)
            {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }
        public ResponseAdminWareHouse setWareHouse(RequestAdminWareHouse req)
        {
            ResponseAdminWareHouse response = new ResponseAdminWareHouse();

            try
            {
                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("WareHouse/adminWareHouse", req);
                response = JsonConvert.DeserializeObject <ResponseAdminWareHouse>(json);

                return(response);
            }
            catch (Exception ex)
            {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }
        public ResponseAdminRoleApplicationList getRoleApplicationList(RequestAdminRoleApplication req, string id)
        {
            ResponseAdminRoleApplicationList response = new ResponseAdminRoleApplicationList();

            try
            {
                // Primero obtener el listado de Roles
                RequestAdminRole      reqRole   = new RequestAdminRole();
                ResponseAdminRoleList resRole   = new ResponseAdminRoleList();
                LogicAdminRole        logicRole = new LogicAdminRole();

                // Obtener el listado completo de Roles
                reqRole.id = 0;
                resRole    = logicRole.getRoleList(reqRole);

                // Si no se manda un Rol, obtener los permisos del primero
                if (id == null)
                {
                    req.idRole = resRole.lst[0].id;
                }
                else
                {
                    req.idRole = int.Parse(id);
                }

                // Obtener el listado completo de opciones
                RequestAdminApplication      reqApp   = new RequestAdminApplication();
                ResponseAdminApplicationList resApp   = new ResponseAdminApplicationList();
                LogicAdminApplication        logicApp = new LogicAdminApplication();

                reqApp.id = 0;
                resApp    = logicApp.getApplicationList(reqApp);

                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("RoleApplication/getAdminRoleApplication", req);
                response = JsonConvert.DeserializeObject <ResponseAdminRoleApplicationList>(json);
                List <SelectListItem> lst = new List <SelectListItem>();

                // Llenar el listado de Roles
                foreach (ResponseAdminRoleDetail r in resRole.lst)
                {
                    lst.Add(new SelectListItem
                    {
                        Text     = r.detail,
                        Value    = r.id.ToString(),
                        Selected = r.id == req.idRole ? true : false
                    });
                }

                // Agregar el listado de Roles
                response.lstRole = lst;
                // Agregar el listado de aplicaciones
                response.lstApplication = resApp.lst;

                return(response);
            }
            catch (Exception ex)
            {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }
Esempio n. 10
0
        public ResponseAdminUser setUser(RequestAdminUser req)
        {
            ResponseAdminUser rUser   = new ResponseAdminUser();
            ResponsePerson    rPerson = new ResponsePerson();

            try
            {
                LogicCommon com      = new LogicCommon();
                string      json     = "";
                int         idPerson = req.idPerson;
                int         idUser   = req.id;

                // Primero Registrar la persona
                if (req.flag != 'N')
                {
                    req.id = idPerson;
                }

                json    = com.HttpPost("Person/crudPerson", req);
                rPerson = JsonConvert.DeserializeObject <ResponsePerson>(json);

                if (rPerson.code == 50000)
                {
                    if (req.flag == 'N')
                    {
                        req.idPerson = rPerson.status;
                    }
                    else
                    {
                        req.id = idUser;
                    }


                    // Completar el nombre completo para el usuario
                    req.name  = req.firstName + " ";
                    req.name += req.secondName == null ? "" : req.secondName + " ";
                    req.name += req.firstLastName == null ? "" : req.firstLastName + " ";
                    req.name += req.secondLastName == null ? "" : req.secondLastName;

                    req.name = req.name.Trim();
                    // Ahora registrar el usuario
                    json  = com.HttpPost("User/adminUser", req);
                    rUser = JsonConvert.DeserializeObject <ResponseAdminUser>(json);

                    // Revertir perfil de la persona, ya que no fue posible crear el usuario
                    if (rUser.code != 50000)
                    {
                    }
                }
                else
                {
                    rUser.code    = -1;
                    rUser.message = "Error creando el perfil de la persona, favor contactar con el administrador del sistema";
                }

                return(rUser);
            }
            catch (Exception ex)
            {
                rUser.code    = -1;
                rUser.message = ex.Message;
            }

            return(rUser);
        }
Esempio n. 11
0
        public ResponseAdminUserList getUserList(RequestAdminUser req)
        {
            ResponseAdminUserList response = new ResponseAdminUserList();

            try
            {
                LogicCommon com  = new LogicCommon();
                string      json = com.HttpPost("User/getAdminUser", req);
                response = JsonConvert.DeserializeObject <ResponseAdminUserList>(json);

                // Cargar el listado completo de Roles
                RequestAdminRole      reqRole    = new RequestAdminRole();
                ResponseAdminRoleList resRole    = new ResponseAdminRoleList();
                LogicAdminRole        logicRole  = new LogicAdminRole();
                List <SelectListItem> lstTmpRole = new List <SelectListItem>();

                // Obtener el listado completo de Roles
                reqRole.id = 0;
                resRole    = logicRole.getRoleList(reqRole);

                // Llenar el listado de Roles
                foreach (ResponseAdminRoleDetail r in resRole.lst)
                {
                    lstTmpRole.Add(new SelectListItem
                    {
                        Text     = r.detail,
                        Value    = r.id.ToString(),
                        Selected = r.id == req.idRole ? true : false
                    });
                }

                // Agregar el listado de Roles
                response.lstRole = lstTmpRole;

                // Cargar el catálogo de tipos de documentos
                RequestAdminClsMaster      reqCls    = new RequestAdminClsMaster();
                ResponseAdminClsMasterList resCls    = new ResponseAdminClsMasterList();
                LogicAdminClsMaster        logicCls  = new LogicAdminClsMaster();
                List <SelectListItem>      lstTmpCls = new List <SelectListItem>();

                // Obtener el catálogo de tipos de documentos
                reqCls.catalogId = "TIPOSDOCUMENTO";
                reqCls.child     = true;
                resCls           = logicCls.getClsMasterList(reqCls);

                // Llenar el listado de acuerdo al catálogo
                foreach (ResponseAdminClsMasterDetail r in resCls.lst)
                {
                    lstTmpCls.Add(new SelectListItem
                    {
                        Text     = r.detail,
                        Value    = r.id.ToString(),
                        Selected = r.id == req.typeDocument ? true : false
                    });
                }

                // Agregar el listado del catálogo documentos
                response.lstTypeDocument = lstTmpCls;


                return(response);
            }
            catch (Exception ex)
            {
                response.code    = -1;
                response.message = ex.Message;
            }

            return(response);
        }