public HttpResponseMessage UpdateBlog([FromBody] PostSerializer post) { try { var res = Entities.PostEdit(post.PostId, post.Content, post.Title).SingleOrDefault(); if (res != null && res.TypeId != 3) { return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = false, Message = "Not a blog" })); } return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = true, Message = "Blog retrieved", Data = res })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = false, Message = ex.Message })); } }
public HttpResponseMessage CreatePost([FromBody] PostSerializer post) { try { var res = Entities.PostCreate(CurrentIdentity.UserId, post.GroupId, post.Title, post.Content, post.TypeId).SingleOrDefault(); if (res == null) { return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = false, Message = "Post has not been created." })); } //var posts = Entities.UserPostsGet(CurrentIdentity.UserId, 1, 10); return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = true, Data = res, Message = "Post has been created." })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ResponseMessage { Success = false, Message = ex.Message })); } }
public HttpResponseMessage UpdatePost([FromBody] PostSerializer post) { try { var res = Entities.PostEdit(post.PostId, post.Content, null).FirstOrDefault(); var resultComment = new Comment { UserId = res.UserId, PostId = res.PostId, Content = res.Content, CreatedAt = res.CreatedAt, FirstName = res.FirstName, LastName = res.LastName, UserPicture = res.UserPicture, Visible = res.Visible, ModifiedAt = res.ModifiedAt, Likes = Entities.Likes.Count(l => l.CommentId == post.PostId), Liked = Entities.Likes.FirstOrDefault( l => l.UserId == CurrentIdentity.UserId.Value && l.CommentId == post.PostId) != null }; return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = true, Message = "Post updated successfully.", Data = resultComment })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ResponseMessage { Success = false, Message = ex.Message })); } }
public HttpResponseMessage EditPost([FromBody] PostSerializer post) { try { var res = Entities.PostEdit(post.PostId, post.Content, null).SingleOrDefault(); return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = true, Message = "Post has been modified.", Data = res })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ResponseMessage { Success = false, Message = ex.Message })); } }
public void CanSerializePostInstance() { var post = new Post { Title = "Lorem Ipsum Dolor", DateCreated = DateTime.Parse("5/18/2013"), DateEdited = DateTime.Parse("5/18/2013"), Content = "Lorem ipsum dolor sit amet, consectetur <b>adipiscing</b> elit. Sed orci ante, tincidunt vitae hendrerit aliquam, molestie in nulla. Vestibulum sit amet mollis libero. Curabitur sit amet porta dui. Proin lectus urna, vulputate ac laoreet ut, scelerisque id neque. Etiam posuere metus et justo vestibulum egestas a id arcu. Suspendisse commodo ipsum ac nisi volutpat posuere facilisis dui pretium. Mauris mollis, felis quis laoreet faucibus, felis eros imperdiet ipsum, et congue mauris erat ac justo. Duis molestie venenatis magna, et convallis elit fermentum sed. Nulla tortor diam, auctor non suscipit at, sagittis ut est. Nam purus felis, hendrerit sit amet sodales sit amet, feugiat at sapien. Donec sed tellus nisl, id suscipit massa. Curabitur iaculis, dui ac mattis cursus, enim eros imperdiet lacus, eget egestas orci dui ut nibh. Aenean in sapien ipsum.", Tags = new[] { "ASP.Net", "C#" } }; var serializer = new PostSerializer(); var serializedString = serializer.Serialize(post); var postSerializer = new PostDeserializer(); var serializedPost = postSerializer.Serialize(serializedString); Assert.IsNotNull(serializedPost); Assert.IsTrue(!string.IsNullOrEmpty(serializedString)); Assert.IsTrue(serializedString.IndexOf("Lorem ipsum dolor sit amet, consectetur <b>adipiscing</b> elit. Sed orci ante, tincidunt vitae hendrerit aliquam, molestie in nulla. Vestibulum sit amet mollis libero. Curabitur sit amet porta dui. Proin lectus urna, vulputate ac laoreet ut, scelerisque id neque. Etiam posuere metus et justo vestibulum egestas a id arcu. Suspendisse commodo ipsum ac nisi volutpat posuere facilisis dui pretium. Mauris mollis, felis quis laoreet faucibus, felis eros imperdiet ipsum, et congue mauris erat ac justo. Duis molestie venenatis magna, et convallis elit fermentum sed. Nulla tortor diam, auctor non suscipit at, sagittis ut est. Nam purus felis, hendrerit sit amet sodales sit amet, feugiat at sapien. Donec sed tellus nisl, id suscipit massa. Curabitur iaculis, dui ac mattis cursus, enim eros imperdiet lacus, eget egestas orci dui ut nibh. Aenean in sapien ipsum.", StringComparison.Ordinal) >= 0); Assert.IsTrue(serializedString.IndexOf("ASP.Net", StringComparison.Ordinal) >= 0); Assert.IsTrue(serializedString.IndexOf("C#", StringComparison.Ordinal) >= 0); }
private IEnumerator Interceptors(Method method, string uri, Payloads payload = null, Dictionary <string, string> pathParams = null, Callback callback = null, Fallback fallback = null) { UnityWebRequest webRequest = new UnityWebRequest(baseUri + uri, method.ToString()); webRequest.SetRequestHeader("Content-Type", "application/json"); webRequest.SetRequestHeader("Authorization", "Bearer " + Token.GetToken()); if (payload != null) { byte[] bodyRaw = Encoding.UTF8.GetBytes(PostSerializer.SerializePostData(payload)); webRequest.uploadHandler = new UploadHandlerRaw(bodyRaw); } webRequest.downloadHandler = new DownloadHandlerBuffer(); yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { if (webRequest.responseCode == 0) { webRequest.Abort(); Request request = new Request(method, uri, payload, pathParams); Resend(request, callback, fallback); } } else if (webRequest.isHttpError) { if (webRequest.responseCode == CODE_BLACKLISTED_USER) { // Save Request, Callback and Fallback State.PendingFullRequestWhileRefreshingToken = new FullRequest( new Request(method, uri, payload, pathParams), callback, fallback ); RefreshToken.Refresh(); } else { var responseJson = webRequest.downloadHandler.text; fallback(webRequest.responseCode, responseJson); } } else { var responseJson = webRequest.downloadHandler.text; callback(webRequest.responseCode, responseJson); } }