예제 #1
0
        protected override void OnHandle(AddZoneCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                ZoneTypeCodes zoneTypeCode;
                if (!Enum.TryParse(command.ZoneType, out zoneTypeCode))
                {
                    throw new ArgumentOutOfRangeException($"Zone type: {command.ZoneType} is not valid");
                }

                Validate(command, uow);
                long siteId = command.SiteId;
                var  site   = uow.Context.
                              FindById <Entities.Sites.Site>(siteId);

                var zone = new Entities.Sites.Zone
                {
                    Name        = command.Name,
                    Title       = command.Title,
                    ZoneType    = zoneTypeCode,
                    IsActive    = command.IsActive,
                    IsPrivate   = !command.IsPublic,
                    Site        = site,
                    Description = command.Description,
                };
                uow.Context.Add(zone);

                uow.Complete();
            }
        }
예제 #2
0
        private void Validate(IPersistenceUnitOfWork uow, Entities.Sites.Zone zoneToDelete)
        {
            long zoneId = zoneToDelete.Id;

            bool hasPosts = uow.Context
                            .Query <Entities.Posts.Post>()
                            .Any(e => e.Zone.Id == zoneId);

            if (hasPosts)
            {
                throw new ValidationException("Zone has posts, please delete them first and try again.");
            }
        }