Example #1
0
        /// <summary>
        /// Send CRUD notifications for a JarsUserRole Entity or Entities
        /// Note! :
        /// This Method is a special method used by the service when ServerEvents are being used.(serviceStack).
        /// If the service does not implement serverEvents this will throw an error.
        /// This will send a notification to all subscribed clients (including the client the request originated from) where the chanel name is the name of the entity type.
        /// This will only process SelectorTypes.store and SelectorTypes.delete notifications.
        /// The notification sent to subscribers will also be a JarsSyncEventStore or JarsSyncEventStore Dto object.
        /// </summary>
        /// <param name="crud">The notification request indicating a store or delete event that will be sent to other subscribers.</param>
        public virtual void Any(JarsUserRolesCrudNotification crud)
        {
            ExecuteFaultHandledMethod(() =>
            {
                //check that the sender has subscribed to the service
                SubscriptionInfo subscriber = ServerEvents.GetSubscriptionInfo(crud.FromSubscriptionId);
                if (subscriber == null)
                {
                    throw HttpError.NotFound($"Subscriber {crud.FromUserId} does not exist.");
                }

                //do some job updates here using the info from the the crud
                IJarsUserRoleRepository _repository = _DataRepositoryFactory.GetDataRepository <IJarsUserRoleRepository>();

                if (crud.Selector == SelectorTypes.store)
                {
                    if (crud.Role != null)
                    {
                        crud.Role = _repository.CreateUpdate(crud.Role, crud.FromUserId);
                        ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Role.ConvertToJarsSyncEventStore());
                    }
                    else
                    {
                        crud.Roles = _repository.CreateUpdateList(crud.Roles, crud.FromUserId).ToList();
                        ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Roles.ConvertToJarsSyncEventStore());
                    }
                }

                if (crud.Selector == SelectorTypes.delete)
                {
                    if (crud.Role != null)
                    {
                        _repository.Delete(crud.Role);
                        ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Role.ConvertToJarsSyncEventDelete());
                    }
                    else
                    {
                        _repository.DeleteList(crud.Roles);
                        ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Roles.ConvertToJarsSyncEventDelete());
                    }
                }
            });
        }
Example #2
0
        /// <summary>
        /// Update or create a single JarsUserRole or a list of Roles, depending on whether the Role or Roles property has got a value set.
        /// If the Role property is set the Role will be created or updated and the Roles property will be ignored.
        /// To create or update more than one Role, assign a list to the Roles property and make sure Role is set to nothing/null.
        /// </summary>
        /// <param name="request">The request containing the Role or Roles that needs to be created or updated</param>
        /// <returns>depending on the values supplied, the updated Role or Roles will be returned.</returns>
        public virtual JarsUserRolesResponse Any(StoreJarsUserRoles request)
        {
            return(ExecuteFaultHandledMethod(() =>
            {
                JarsUserRolesResponse response = new JarsUserRolesResponse();
                IJarsUserRoleRepository _repository = _DataRepositoryFactory.GetDataRepository <IJarsUserRoleRepository>();
                bool isSingleEnt = false;
                if (request.Role != null)
                {
                    isSingleEnt = true;
                }

                if (request.Role != null)
                {
                    response.Role = _repository.CreateUpdate(request.Role, request.ModifiedBy);
                }
                else
                {
                    response.Roles = _repository.CreateUpdateList(request.Roles, request.ModifiedBy).ToList();
                }
                return response;
            }));
        }