Example #1
0
        public async Task <HttpResponseMessage> MenuRightsToken(GroupsDataModel model)
        {
            Thread.CurrentThread.CurrentCulture = culture;

            List <MenuRightsModel> resultRightsModel = null;

            try
            {
                bool isAdmin = true;
                if (!await Authentication.isAdmin(User, Request))
                {
                    isAdmin = false;
                }

                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    using (SqlConnection connection1 = new SqlConnection(connetionString))
                    {
                        await connection1.OpenAsync();

                        resultRightsModel = new List <MenuRightsModel>();
                        if (User.IsInRole("Administrador"))
                        {
                            AddRight("Configuracion/CompaƱias", resultRightsModel);
                            AddRight("Configuracion/Menu", resultRightsModel);
                            AddRight("Configuracion/Grupos", resultRightsModel);
                            AddRight("Configuracion/Usuarios", resultRightsModel);
                        }
                        else
                        {
                            await GetMenuRights(connection1, User.Identity.GetUserId(), resultRightsModel, isAdmin);
                        }
                    }
                    scope.Complete();
                }
            }
            catch (TransactionAbortedException ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }
            catch (Exception ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }


            return(Request.CreateResponse(System.Net.HttpStatusCode.OK, resultRightsModel));
        }
Example #2
0
        public async Task <HttpResponseMessage> Groups(GroupsDataModel model)
        {
            Thread.CurrentThread.CurrentCulture = culture;

            List <GroupsQueryModel> resultSeachModel     = null;
            GroupsByIdModel         resultSeachByIdModel = null;
            Grupos proxy = new Grupos();

            try
            {
                if (!await Authentication.isAdmin(User, Request))
                {
                    Authentication auth = new Authentication();

                    if (!await auth.AccesRights(User.Identity.GetUserId(), "groups", model.type))
                    {
                        return(Request.CreateResponse(System.Net.HttpStatusCode.Unauthorized));
                    }
                    auth = null;
                }

                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    using (SqlConnection connection1 = new SqlConnection(connetionString))
                    {
                        await connection1.OpenAsync();

                        if (model.type == 1)
                        {
                            resultSeachModel = new List <GroupsQueryModel>();
                            await proxy.SearchQuery(model.search, resultSeachModel, connection1);
                        }
                        else if (model.type == 2)
                        {
                            resultSeachByIdModel = new GroupsByIdModel();
                            await proxy.ById(model.byId, connection1, resultSeachByIdModel);
                        }
                        else if (model.type == 3)
                        {
                            await proxy.New(connection1, model.update);
                        }
                        else if (model.type == 4)
                        {
                            await proxy.Update(connection1, model.update);
                        }
                        else if (model.type == 5)
                        {
                            await proxy.UpdateIsActive(connection1, model.isActive);
                        }
                    }
                    scope.Complete();
                }
            }
            catch (TransactionAbortedException ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }
            catch (Exception ex)
            {
                ErrorModel _errors = new ErrorModel();
                _errors.message = ex.Message;
                return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors));
            }

            if (model.type == 1)
            {
                return(Request.CreateResponse(System.Net.HttpStatusCode.OK, resultSeachModel));
            }
            else if (model.type == 2)
            {
                return(Request.CreateResponse(System.Net.HttpStatusCode.OK, resultSeachByIdModel));
            }

            return(Request.CreateResponse(System.Net.HttpStatusCode.OK));
        }