Exemplo n.º 1
0
        public IQueryable <ModelUserRole> GetUserRolesByUser(string username)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new Exception("An error occured and user could not be identified.");
            }
            var model = new ModelUserRole();

            return(model.Get(_ctx).Where(x => x.UserRoleActive == true && x.Username == username));
        }
Exemplo n.º 2
0
        public ModelUserRole GetUserRole(string username, string rolename)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new Exception("An error occured and user could not be identified.");
            }
            if (string.IsNullOrWhiteSpace(rolename))
            {
                throw new Exception("An error occured and role could not be identified.");
            }
            var model = new ModelUserRole();

            return(model.Get(_ctx).FirstOrDefault(x => x.UserRoleActive == true && x.Username == username && x.RoleName == rolename));
        }
Exemplo n.º 3
0
        public void CreateUserRole(ModelUserRole model)
        {
            using (var transaction = _ctx.Database.BeginTransaction())
            {
                try
                {
                    model.UserRoleActive = true;

                    var entity = model.ToEntity();

                    _ctx.Insert(entity);
                    _ctx.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new ArgumentException(e.Message);
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateUserRole(ModelUserRole model)
        {
            using (var transaction = _ctx.Database.BeginTransaction())
            {
                try
                {
                    var entity = _ctx.UserRoles.FirstOrDefault(x => x.URID == model.URID);

                    model.Update(entity);

                    _ctx.Update(entity);
                    _ctx.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new ArgumentException(e.Message);
                }
            }
        }
Exemplo n.º 5
0
        public void CreateUserRole(ModelUserRole model, string username, string rolename)
        {
            //using (var transaction = _ctx.Database.BeginTransaction())
            //{
            try
            {
                model.UserRoleActive = true;
                model.Username       = username;
                model.RoleName       = rolename;

                var entity = model.ToEntity();

                _ctx.Insert(entity);
                _ctx.SaveChanges();

                //transaction.Commit();
            }
            catch (Exception e)
            {
                //transaction.Rollback();
                throw new ArgumentException(e.Message);
            }
            //}
        }
Exemplo n.º 6
0
        public ModelUserRole GetUserRole(int urid)
        {
            var model = new ModelUserRole();

            return(model.Get(_ctx).FirstOrDefault(x => x.URID == urid));
        }
Exemplo n.º 7
0
        public IQueryable <ModelUserRole> ReadUserRoles()
        {
            var model = new ModelUserRole();

            return(model.Get(_ctx));
        }