コード例 #1
0
        public async Task Handle(AddServiceCommand message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            ServiceAggregateOccurrence occurrence = null;

            if (message.Occurrence != null)
            {
                occurrence = new ServiceAggregateOccurrence
                {
                    Id        = Guid.NewGuid().ToString(),
                    Days      = message.Occurrence.Days,
                    StartDate = message.Occurrence.StartDate,
                    EndDate   = message.Occurrence.EndDate,
                    StartTime = message.Occurrence.StartTime,
                    EndTime   = message.Occurrence.EndTime
                };
            }

            var service = new ServiceAggregate
            {
                Id               = message.Id,
                Name             = message.Name,
                Description      = message.Description,
                PartialImagesUrl = message.Images,
                Price            = message.Price,
                Tags             = message.Tags,
                ShopId           = message.ShopId,
                CreateDateTime   = message.CreateDateTime,
                UpdateDateTime   = message.UpdateDateTime,
                TotalScore       = 0,
                AverageScore     = 0,
                Occurrence       = occurrence
            };

            if (!await _serviceRepository.Add(service))
            {
                return;
            }

            _eventPublisher.Publish(new ServiceAddedEvent
            {
                Id             = message.Id,
                Name           = message.Name,
                Description    = message.Description,
                Price          = message.Price,
                ShopId         = message.ShopId,
                CreateDateTime = message.CreateDateTime,
                UpdateDateTime = message.UpdateDateTime,
                CommonId       = message.CommonId
            });
        }
コード例 #2
0
        public static ServiceAggregate ToAggregate(this Service service)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            ServiceAggregateOccurrence occurrence = null;

            if (service.Occurrence != null)
            {
                occurrence = service.Occurrence.ToAggregate();
            }

            IEnumerable <string> images = null;

            if (service.Images != null)
            {
                images = service.Images.Select(i => i.PartialPath);
            }

            IEnumerable <string> tags = null;

            if (service.Tags != null)
            {
                tags = service.Tags.Select(t => t.TagName);
            }

            ICollection <ServiceComment> comments = null;

            if (service.Comments != null)
            {
                comments = service.Comments.Select(c => c.ToAggregateService()).ToList();
            }

            return(new ServiceAggregate
            {
                Description = service.Description,
                Id = service.Id,
                Name = service.Name,
                Occurrence = occurrence,
                PartialImagesUrl = images,
                Price = service.Price,
                ShopId = service.ShopId,
                Tags = tags,
                AverageScore = service.AverageScore,
                TotalScore = service.TotalScore,
                Comments = comments,
                CreateDateTime = service.CreateDateTime,
                UpdateDateTime = service.UpdateDateTime
            });
        }