Exemple #1
0
        public async Task <PostDTO> AddAsync(PostDTO dtoModel)
        {
            await this.ValidateAsync(dtoModel);

            Post post = new Post();

            dtoModel.DateCreated      = DateTime.Now;
            dtoModel.LastDateModified = DateTime.Now;
            PostMapper.MapPostFromPostDto(ref post, ref dtoModel);
            this.repository.Add(post);
            await this.repository.SaveChangesAsync();

            dtoModel.Id = post.Id;
            return(dtoModel);
        }
Exemple #2
0
        public async Task <PostDTO> UpdateAsync(PostDTO dtoModel)
        {
            await this.ValidateAsync(dtoModel);

            var postEntity = await this.repository.Get(dtoModel.Id).FirstOrDefaultAsync();

            if (postEntity == null)
            {
                throw new Exception("Blog for update not found");
            }
            dtoModel.LastDateModified = DateTime.Now;
            PostMapper.MapPostFromPostDto(ref postEntity, ref dtoModel);
            this.repository.Update(postEntity);
            await this.repository.SaveChangesAsync();

            return(dtoModel);
        }