Beispiel #1
0
 public OkObjectResult AddPost(PostJsonModel model)
 {
     try
     {
         var post = mapper.Map <PostJsonModel, Post>(model);
         service.Insert(post);
         return(Ok(model));
     }
     catch (Exception ex)
     {
         return(Ok(new PostJsonModel(false, ex.Message)));
     }
 }
Beispiel #2
0
        public OkObjectResult UpdatePost(string id, PostJsonModel model)
        {
            try
            {
                if (id != model.Id)
                {
                    return(Ok(new PostJsonModel(false, "Bad request")));
                }

                var post   = mapper.Map <PostJsonModel, Post>(model);
                var result = service.Update(post);
                if (result)
                {
                    return(Ok(model));
                }
                return(Ok(new PostJsonModel(false, "Something went wrong")));
            }
            catch (Exception ex)
            {
                return(Ok(new PostJsonModel(false, ex.Message)));
            }
        }
        public async Task <OkObjectResult> CreatePost(PostJsonModel post)
        {
            var response = await PostResponse("MDB", "post", post);

            return(Ok(response));
        }
        public async Task <OkObjectResult> EditPost(string id, PostJsonModel post)
        {
            var response = await PutResponse("MDB", $"post/{id}", post);

            return(Ok(response));
        }