Пример #1
0
        public dynamic SavePost([FromBody] Newtonsoft.Json.Linq.JObject param)
        {
            dynamic result = null;

            try
            {
                dynamic dd = param;
                int     id = dd.post_id;

                string   user_photo   = dd.user_photo;
                int      uploader_id  = dd.uploader_id;
                string   content_text = dd.content_text;
                int      photo_count  = dd.photo_count;
                DateTime created_date = DateTime.Now;

                int    post_detail_id = dd.post_detail_id;
                string photo          = dd.photo;


                tbl_post        p  = new tbl_post();
                tbl_post_detail pd = new tbl_post_detail();

                p.post_id      = id;
                p.user_photo   = user_photo;
                p.uploader_id  = uploader_id;
                p.content_text = content_text;
                p.photo_count  = photo_count;
                p.created_date = created_date;

                pd.post_detail_id = post_detail_id;
                pd.post_id        = id;
                pd.content_text   = content_text;
                pd.photo          = photo;

                _repositoryWrapper.Post_Repository.Create(p);
                _repositoryWrapper.Post_Detail_Repository.Create(pd);
                result = new { Status = 1, Message = "Save Successfully", data = new { } };
            }
            catch (Exception ex)
            {
                result = new { Status = 0, Message = "Save Fail", data = new { } };
                Console.WriteLine(ex.Message);
            }

            return(result);
        }
Пример #2
0
        public dynamic DeletePost([FromBody] Newtonsoft.Json.Linq.JObject param)
        {
            dynamic result = null;

            try
            {
                dynamic dd = param;
                int     id = dd.post_id;

                string   user_photo   = dd.user_photo;
                int      uploader_id  = dd.uploader_id;
                string   content_text = dd.content_text;
                int      photo_count  = dd.photo_count;
                DateTime created_date = DateTime.Now;

                int    post_detail_id = dd.post_detail_id;
                string photo          = dd.photo;

                dynamic  main1 = _repositoryWrapper.Post_Repository.GetPostByID(id);
                tbl_post p     = main1 as tbl_post;
                _repositoryWrapper.Post_Repository.Delete(p);
                List <Post_Detail_Repository> main2 = _repositoryWrapper.Post_Detail_Repository.GetPostDetailByPostID(id);
                foreach (var item in main2)
                {
                    _repositoryWrapper.Post_Detail_Repository.Delete(item);
                }
                ;
                result = new { Status = 1, Message = "Delete Successfully", data = new { } };
            }
            catch (Exception ex)
            {
                result = new { Status = 0, Message = "Delete Fail", data = new { } };
                Console.WriteLine(ex.Message);
            }
            return(result);
        }