public static PostDto Map(Post post) { return new PostDto() { Id = post.Id, Title = post.Title, Text = post.Text, Created = post.Created, AuthorId = post.AuthorId }; }
public int? SavePost(SavePostDto postDto) { return UnitOfWork.Do(uow => { if (postDto.Id == 0) { var post = new Post() { Title = postDto.Title, Text = postDto.Text, Created = DateTime.Now, AuthorId = uow.Repo<User>().AsQueryable().First(t=>t.Id==postDto.AuthodId).Id }; var found = uow.Repo<Post>().AsQueryable().FirstOrDefault(t => t.Title == postDto.Title); if (found == null) { return (int)uow.Repo<Post>().Insert<decimal>(post); } } else { var found = uow.Repo<Post>().AsQueryable().FirstOrDefault(t => t.Id == postDto.Id); if (found != null) { found.Title = postDto.Title; found.Text = postDto.Text; found.AuthorId = uow.Repo<User>().AsQueryable().First(t => t.Id == postDto.AuthodId).Id; uow.Repo<Post>().Update(found); return found.Id; } } return (int?)null; }); }