예제 #1
0
        public async Task CreateProjectionAsync(ICreatedEvent <TEntity> @event)
        {
            TableEntity tableEntity;

            if (@event.GetType() == typeof(ScorecardInfoCreated))
            {
                var scorecardInfo = new ScorecardInfo(@event as ScorecardInfoCreated);
                tableEntity = new ScorecardInfoTableEntity(
                    scorecardInfo.PlayerId,
                    scorecardInfo.Id)
                {
                    CourseId = scorecardInfo.CourseId,
                    Data     = JsonConvert.SerializeObject(scorecardInfo),
                    Date     = scorecardInfo.Date.DateTime
                };
            }
            else
            {
                var entity = (TEntity)Activator.CreateInstance(typeof(TEntity), @event);
                tableEntity = new ModelTableEntity <TEntity>(entity.PlayerId, entity.Id)
                {
                    Data = JsonConvert.SerializeObject(entity),
                };
            }

            var result = await Options.ExecuteWithTableAsync(
                typeof(TEntity).Name,
                TableOperation.Insert(tableEntity));

            if (!result.HttpStatusCode.IsSuccessCode())
            {
                // TODO: log insert failure
            }
        }
예제 #2
0
        public async Task CreateProjectionAsync(ICreatedEvent <TEntity> @event)
        {
            if (IgnoreEntityType())
            {
                return;
            }

            switch (@event)
            {
            case CourseCreated c:
                Context.Courses.Add(new CourseDocument(c));
                break;

            case ScorecardCreated s:
                Context.Scorecards.Add(new ScorecardDocument(s));
                break;
            }

            await Context.SaveChangesAsync();
        }