public void Add(string message) { Check(); if (loggedIn) { myBlog.Add(message); } }
protected void AddUpdateButton_Click(object sender, EventArgs e) { if (Master.IsRefresh) { return; } if (TitleTextBox.Text.Trim() == string.Empty || TextTextBox.Text.Trim() == string.Empty) { ErrorLabel.Visible = true; return; } if (id == null) { Blog.Add(TitleTextBox.Text.Trim(), TextTextBox.Text.Trim()); } else { Blog.Update((int)id, TitleTextBox.Text.Trim(), TextTextBox.Text.Trim()); } Response.Redirect("~/_admin/manageblog.aspx"); }
public IActionResult Create(BlogViewModel newBlog) { if (_uid == null) { return(RedirectToAction("Login", "Home")); } if (ModelState.IsValid) { if (!AreImagesValid(newBlog.Imgs)) { return(View()); } Blog blog = new Blog(); blog.Add(newBlog); dbContext.Blogs.Add(blog); dbContext.SaveChanges(); CreateBlogImgRows(blog.BlogId, newBlog.Imgs); return(RedirectToAction("Index")); } return(View()); }
public async Task Blog_CRUD_Test() { if (_fixture.DOTNET_RUNNING_IN_CONTAINER) { return; //pass on fake DB with no data } // Arrange string antiforgery_token; List <KeyValuePair <string, string> > data; using (var create_get_response = await _client.GetAsync($"{_fixture.AppRootPath}{BlogsController.ASPX}/{nameof(BlogsController.Create)}/", HttpCompletionOption.ResponseContentRead)) { // Assert create_get_response.EnsureSuccessStatusCode(); antiforgery_token = await PostRequestHelper.ExtractAntiForgeryToken(create_get_response); // Arrange var now = DateTime.Now; data = new Blog { BlogId = 0, Post = new[] { new Post { Content = $"aaaa {now}", Title = "titla" } }, Url = $"http://www.inernetAt-{now.Year}-{now.Month}-{now.Day}.com/Content{now.Hour}-{now.Minute}-{now.Second}" }.ToDictionary().ToList(); data.Add(new KeyValuePair <string, string>("__RequestVerificationToken", antiforgery_token)); using (var formPostBodyData = new FormUrlEncodedContent(data)) { PostRequestHelper.CreateFormUrlEncodedContentWithCookiesFromResponse(formPostBodyData.Headers, create_get_response); // Act using (var redirect = await _client.PostAsync($"{_fixture.AppRootPath}{BlogsController.ASPX}/{nameof(BlogsController.Create)}/", formPostBodyData)) { // Assert Assert.NotNull(redirect); Assert.Equal(HttpStatusCode.Redirect, redirect.StatusCode); Assert.Contains($"{_fixture.AppRootPath}{BlogsController.ASPX}", redirect.Headers.GetValues("Location").FirstOrDefault()); } } int last_inserted_id; string last_inserted_ProtectedID; using (var index_response = await _client.GetAsync($"{_fixture.AppRootPath}{BlogsController.ASPX}/", HttpCompletionOption.ResponseContentRead)) { var responseString = await index_response.Content.ReadAsStringAsync(); MatchCollection matches = Regex.Matches(responseString, @"\<form method=""post"" class=""blogForm"" data-id=""([0-9].*)""\>"); Assert.NotEmpty(matches); var ids = new List <int>(matches.Count); foreach (Match m in matches) { var match_count = m.Success ? m.Groups[1].Captures.Count : 0; Assert.True(match_count > 0); var id = int.Parse(m.Groups[1].Captures[match_count - 1].Value); ids.Add(id); } last_inserted_id = ids.OrderByDescending(_ => _).First(); Match match = Regex.Match(responseString, $@"\<input type=""hidden"" id=""ProtectedID_{last_inserted_id}"" name=""ProtectedID"" value=""([^""]+)"" \/\>"); Assert.True(match.Success && match.Groups[1].Captures.Count > 0); last_inserted_ProtectedID = match.Groups[1].Captures[0].Value; } data = new DecoratedBlog { BlogId = last_inserted_id, ProtectedID = last_inserted_ProtectedID, Url = $"http://www.changed-{now.Year + 1}-{now.Month}-{now.Day}.com/NewContent{now.Hour}-{now.Minute}-{now.Second}" }.ToDictionary().ToList(); data.Add(new KeyValuePair <string, string>("__RequestVerificationToken", antiforgery_token)); using (var formPostBodyData = new FormUrlEncodedContent(data)) { PostRequestHelper.CreateFormUrlEncodedContentWithCookiesFromResponse(formPostBodyData.Headers, create_get_response); using (var response = await _client.PostAsync($"{_fixture.AppRootPath}{BlogsController.ASPX}/{nameof(BlogActionEnum.Edit)}/{last_inserted_id}/true", formPostBodyData)) { Assert.NotNull(response); response.EnsureSuccessStatusCode(); Assert.Contains("application/json", response.Content.Headers.GetValues("Content-Type").FirstOrDefault()); Assert.Contains("{\"blogId\":" + last_inserted_id + ",\"url\":\"" + $"http://www.changed-{now.Year + 1}-{now.Month}-{now.Day}.com/NewContent{now.Hour}-{now.Minute}-{now.Second}", await response.Content.ReadAsStringAsync()); } } data = new DecoratedBlog { BlogId = last_inserted_id, ProtectedID = last_inserted_ProtectedID, }.ToDictionary().ToList(); data.Add(new KeyValuePair <string, string>("__RequestVerificationToken", antiforgery_token)); using (var formPostBodyData = new FormUrlEncodedContent(data)) { PostRequestHelper.CreateFormUrlEncodedContentWithCookiesFromResponse(formPostBodyData.Headers, create_get_response); using (var response = await _client.PostAsync($"{_fixture.AppRootPath}{BlogsController.ASPX}/{nameof(BlogActionEnum.Delete)}/{last_inserted_id}/true", formPostBodyData)) { Assert.NotNull(response); response.EnsureSuccessStatusCode(); Assert.Contains("application/json", response.Content.Headers.GetValues("Content-Type").FirstOrDefault()); Assert.Equal("\"deleted\"", await response.Content.ReadAsStringAsync()); } } } //end using (var create_get_response }
public void Add(string message) { MyOpenB.Add(message); }