protected override void OnHandle(AddPostSerieCommand command) { using (var uow = UowFactory.Create()) { Validate(uow, command); var siteId = command.SiteId; var site = uow.Context.Query <Entities.Sites.Site>().SingleOrDefault(s => s.Id == siteId); var postSerie = new PostSerie { Site = site, Name = command.Name, Title = command.Title, Description = command.Description, IsPrivate = command.IsPrivate }; uow.Context.Add(postSerie); uow.Complete(); } }
protected override void OnHandle(NewPostCommand command) { string title = command.Title; var authorIdentity = command.UserName; using (var uow = UowFactory.Create()) { Validate(command, uow); var user = uow.Context .Query <Entities.Security.User>() .SingleOrDefault(u => u.UserName == authorIdentity); var author = user.Person != null?user.Person.GetFullName() : user.UserName; var site = uow.Context.FindById <Entities.Sites.Site>(command.SiteId); var zone = uow.Context.FindById <Entities.Sites.Zone>(command.ZoneId); PostSerie serie = null; if (command.SerieId > 0) { serie = uow.Context.FindById <PostSerie>(command.SerieId); } var postStatus = PostStatus.Saved; // TODO: figure out the next status, based on user and workflow config var postFormat = ContentFormats.Html; var postTags = (command.TagsCommaSeparated ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(t => t.Trim()) .ToList(); var tagEntities = new HashSet <Tag>(); foreach (var tagName in postTags) { var tagEntity = uow.Context.Query <Tag>().FirstOrDefault(t => t.Name == tagName); if (tagEntity == null) { // TODO: send AddTag command instead tagEntity = new Tag { Name = tagName, Site = site }; uow.Context.Add(tagEntity); } tagEntities.Add(tagEntity); } var nowDate = DateTime.Today.ToUniversalTime(); var newPost = new Entities.Posts.Post { Site = site, Zone = zone, Name = title, Title = title, MetaTitle = command.MetaTitle ?? title, MetaDescription = command.MetaDescription, Author = author, Serie = serie, Created = nowDate, Creator = user, PublishDate = postStatus == PostStatus.Published ? (DateTime?)nowDate : null, EffectiveDate = postStatus == PostStatus.Published ? (DateTime?)nowDate : null, Status = postStatus, Format = postFormat, IsPrivate = command.IsPrivate, IsDiscussionEnabled = command.IsDiscussionEnabled, IsAnonymousCommentAllowed = command.IsAnonymousCommentAllowed, IsRatingEnabled = command.IsRatingEnabled, IsContentBinary = false, IsPingbackEnabled = true, IsTrackbackEnabled = true, IsChromeHidden = false, }; command.Links .ForEach(l => newPost.Links.Add(new PostLink { Type = l.Key, Ref = l.Value, Post = newPost })); tagEntities .ForEach(tag => newPost.Tags.Add(tag)); newPost.Revise(); newPost.LatestRevision.Summary = command.ContentSummary; newPost.LatestRevision.Body = command.Content; newPost.LatestRevision.Reviser = user; newPost.LatestRevision.Author = author; uow.Context.Add(newPost); uow.Complete(); } }