Exemple #1
0
        public ServiceResult <BlogPostResponseModel> Add(BlogPostRequestModel blogPostModel)
        {
            var serviceResult = new ServiceResult <BlogPostResponseModel>();

            try
            {
                var entity = new BlogPost()
                {
                    Body        = blogPostModel.Body,
                    CreatedDate = DateTime.Now,
                    IsActive    = true,
                    IsDeleted   = false,
                    Title       = blogPostModel.Title,
                    TopicId     = blogPostModel.TopicId,
                    SectionId   = blogPostModel.SectionId
                };
                serviceResult.data       = _mapper.Map <BlogPostResponseModel>(_blogPostRepository.AddWithCommit(entity));
                serviceResult.resultType = ServiceResultType.Success;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Exception:BlogPost/Add");
                serviceResult.message    = e.Message;
                serviceResult.resultType = ServiceResultType.Fail;
            }

            return(serviceResult);
        }