Ejemplo n.º 1
0
        public async Task <Response <Empty> > Handle(CloseSchemaCommand request, CancellationToken cancellationToken)
        {
            var schema = await _shopStore.GetSchema(request.SchemaId);

            // todo validate if user allowed to close schema

            if (schema.ShopId != request.ShopId)
            {
                return(Response.Fail("Invalid Schema"));
            }

            schema.State = SchemaState.Closed;

            return(Response.Ok("Schema Closed"));
        }
Ejemplo n.º 2
0
        public async Task <Response <Empty> > Handle(ActivateSchemaCommand request, CancellationToken cancellationToken)
        {
            if (!await _store.UserCanActivateSchema(request.UserId, request.ShopId))
            {
                return(Response.Fail("Not Allowed to activate schema"));
            }

            var schema = await _store.GetSchema(request.SchemaId);

            schema.State = SchemaState.Active;
            await _store.Save();

            // todo send some notifications to interested users

            return(Response.Ok("Schema Activated"));
        }
Ejemplo n.º 3
0
        public async Task <Response <SchemaProgress> > Handle(
            JoinSchemaCommand request,
            CancellationToken cancellationToken)
        {
            var schema = await _shopStore.GetSchema(request.SchemaId);

            var assignedSchema = SchemaFactory.Resolve(schema);

            if (!assignedSchema.Valid(_dateTime))
            {
                return(Response.Fail <SchemaProgress>("Schema not valid"));
            }

            if (await _userStore.InSchemaAsync(request.UserId, request.SchemaId))
            {
                return(Response.Fail <SchemaProgress>("Schema already joined"));
            }

            var progress = await _userStore.CreateSchemaProgressAsync(request.UserId, request.SchemaId);

            return(Response.Ok(progress, "Schema Joined"));
        }
        public async Task <Response <string> > Handle(InitiateRedemptionCommand request, CancellationToken cancellationToken)
        {
            var progress = await _userStore.GetProgressAsync(request.UserId, request.SchemaId);

            var schema = await _shopStore.GetSchema(progress.SchemaId);

            var assignedSchema = SchemaFactory.Resolve(schema);

            if (!assignedSchema.Valid(_dateTime))
            {
                return(Response.Fail <string>("Schema not valid"));
            }

            if (!assignedSchema.ReachedGoal(progress.Progress))
            {
                return(Response.Fail <string>("Goal not reached"));
            }

            var code = await _codeStore.CreateRedemptionCode();

            return(Response.Ok(code, "Code Created"));
        }
        public async Task <Response <Empty> > Handle(RewardCustomerCommand request, CancellationToken cancellationToken)
        {
            var progress = await _userStore.GetProgressAsync(request.UserId, request.SchemaId);

            var schema = await _shopStore.GetSchema(progress.SchemaId);

            var assignedSchema = SchemaFactory.Resolve(schema);

            if (!assignedSchema.Valid(_dateTime))
            {
                return(Response.Fail("Schema not valid"));
            }

            var result = await _codeStore.ValidateRewardCode(schema.ShopId, request.Code);

            if (!result.Success)
            {
                return(Response.Fail("Invalid Code"));
            }

            progress.Progress++;
            return(Response.Ok("Complete"));
        }