示例#1
0
        public void DisableCommentEntry(int id)
        {
            var entry = CommentEntries.FirstOrDefault(e => e.CommentEntryId == id);

            if (entry != null)
            {
                entry.Disabled = true;
                SaveChanges();
            }
        }
示例#2
0
        public int NewCommentEntryNumber()
        {
            var entry = new CommentEntry
            {
                AllowPost = true,
                Disabled  = false
            };

            CommentEntries.Add(entry);
            SaveChanges();

            return(entry.CommentEntryId);
        }
        public async Task <Response> PostCommentEntry(string urlBase, string servicePrefix, string controller, CommentEntries commentEntries, string userToken)
        {
            try
            {
                HttpClient client = new HttpClient
                {
                    BaseAddress = new Uri(urlBase),
                };

                var jsonObject = new
                {
                    title    = commentEntries.Title,
                    blogtext = commentEntries.BlogText,
                    userId   = commentEntries.UserId,
                    country  = commentEntries.Country
                };



                var json          = JsonConvert.SerializeObject(jsonObject);
                var contentString = new StringContent(json, Encoding.Default, "application/json");

                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", userToken);

                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, contentString);

                string result = await response.Content.ReadAsStringAsync();


                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = result,
                    });
                }


                return(new Response
                {
                    IsSuccess = true,
                    Result = result,
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }