Пример #1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext);

            arrRoles = _Roles.Split(',');

            JwtDecodeModel model = (JwtDecodeModel)Thread.CurrentPrincipal;

            bool estaEnRol = false;

            foreach (String r in arrRoles)
            {
                if (model.IsInRole(r.Trim()))
                {
                    estaEnRol = true;
                    break;
                }
            }

            if (!estaEnRol)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                              ResponseUtil.CreaRespuestaError(401, "No tiene permisos para esta acción", "Error de autorización"));
            }
        }
Пример #2
0
        public GenericResponse <InfoPrincipalModel> InfoPrincipal()
        {
            GenericResponse <InfoPrincipalModel> response = new GenericResponse <InfoPrincipalModel>();
            JwtDecodeModel model = (JwtDecodeModel)Thread.CurrentPrincipal;

            try
            {
                bool esVendedor = false;

                esVendedor = model.Roles.Count() == 1 && model.IsInRole("Vendedor");


                ProductoServicio  prodServicio = new ProductoServicio();
                VentaServicio     ventServicio = new VentaServicio();
                ClienteServicio   cliServicio  = new ClienteServicio();
                PromocionServicio promServicio = new PromocionServicio();

                InfoPrincipalModel data = new InfoPrincipalModel();
                data.CantClientes   = cliServicio.Listar("").Count();
                data.CantProductos  = prodServicio.Listar("", 0).Count();
                data.CantVentas     = esVendedor ? ventServicio.Listar("", model.Id).Count() :  ventServicio.Listar("", 0).Count();
                data.CantUsuarios   = esVendedor ? 0 :  servicio.Listar("").Count();
                data.PromosActuales = promServicio.Listar("", 1);
                data.ProdBajoStock  = prodServicio.Listar("", 1);

                response.Data    = data;
                response.Codigo  = 200; // OK
                response.Error   = false;
                response.Mensaje = "OK";
            }
            catch (Exception ex)
            {
                throw new CustomResponseException(ex.Message, 500);
            }
            return(response);
        }
Пример #3
0
        public static bool EsVendedor()
        {
            JwtDecodeModel model = (JwtDecodeModel)Thread.CurrentPrincipal;

            return(model.Roles.Count() == 1 && model.IsInRole("Vendedor"));
        }