Пример #1
0
        public bool Create(String token, DiaryPost post)
        {
            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(BASE_URL);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                CreateDiaryRequest diaryRequest = new CreateDiaryRequest
                {
                    Token    = token,
                    Title    = post.Title,
                    IsPublic = post.IsPublic,
                    Text     = post.Text
                };

                HttpResponseMessage response = client.PostAsync("diary/create", new StringContent(JsonConvert.SerializeObject(diaryRequest), Encoding.UTF8, "application/json")).Result;

                return(response.IsSuccessStatusCode);
            }
            catch
            {
                return(false);
            }
        }
        public IActionResult Edit(DiaryPost post)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", post));
            }

            RestClient rc      = new RestClient();
            var        success = rc.Create(HttpContext.Session.GetString(SessionState.SessionKeyToken), post);

            return(RedirectToAction(nameof(MyDiaryController.Index), "MyDiary"));
        }
Пример #3
0
        public bool Edit(String token, DiaryPost post)
        {
            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(BASE_URL);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                AdjustDiaryPermissionRequest diaryRequest = new AdjustDiaryPermissionRequest
                {
                    Token    = token,
                    Id       = post.Id.ToString(),
                    IsPublic = !post.IsPublic
                };

                HttpResponseMessage response = client.PostAsync("diary/permission", new StringContent(JsonConvert.SerializeObject(diaryRequest), Encoding.UTF8, "application/json")).Result;

                return(response.IsSuccessStatusCode);
            }
            catch
            {
                return(false);
            }
        }