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")); }