public IActionResult CreatePost(CreatePostRequestModel newPost) { var user = _users.GetById(newPost.UserId); _posts.CreatePost(newPost, user); return(RedirectToAction("PostsPage")); }
public void PerformQueryTestExceptions(string quote, string market, EBuySell recommend, string price, EAccessMode access, string content, string forecast, string file) { Assert.Throws <ArgumentNullException>(() => { var model = new CreatePostRequestModel(quote, market, recommend, price, access, content, forecast, file); }); }
public async Task <ActionResult> Create(CreatePostRequestModel model) { var userId = this.currentUser.GetId(); var postId = await this.postsService.Create(model.Description, model.ImageUrl, userId); return(this.Created(nameof(this.Create), postId)); }
public void GetStringForecastTimeFromStringTest(string forecast, string expected) { CreatePostRequestModel model = new CreatePostRequestModel("BMW", string.Empty, EBuySell.Sell, "110.0", EAccessMode.Private, "Content", forecast); var actual = typeof(CreatePostRequestModel).GetRuntimeProperties().First(f => f.Name.Equals("Forecast")); string act = actual.GetValue(model).ToString(); Assert.AreEqual(expected, act); }
public IActionResult CreatePost(CreatePostRequestModel newPost) { if (!ModelState.IsValid) { return(View("CreatePostPage", newPost)); } _posts.CreatePost(newPost); return(RedirectToAction("PostsPage")); }
public void CreatePost(CreatePostRequestModel postModel) { _context.Posts.Add(new Post { ImageUrl = postModel.ImageUrl, Message = postModel.Message, PostedAt = DateTime.Now, UserId = postModel.UserId, }); _context.SaveChanges(); }
public void CreatePost(CreatePostRequestModel postModel, User postedBy) { _context.Posts.Add(new Post { ImageUrl = postModel.ImageUrl, ImageAlt = postModel.ImageAlt, Message = postModel.Message, PostedAt = DateTime.Now, User = postedBy, }); _context.SaveChanges(); }
public Post CreatePost(CreatePostRequestModel postModel) { var insertResult = _context.Posts.Add(new Post { ImageUrl = postModel.ImageUrl, Message = postModel.Message, PostedAt = DateTime.Now, UserId = postModel.UserId, }); _context.SaveChanges(); return(insertResult.Entity); }
public IActionResult CreatePost([FromBody] CreatePostRequestModel newPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var post = _posts.CreatePost(newPost); var url = Url.Action("PostDetails", new { id = post.Id }); var postResponse = new PostResponseModel(post); return(Created(url, postResponse)); }
public string SaveProfile([ModelBinder(Name = "json")] CreatePostRequestModel model) { string a = ""; foreach (var image in model.Image) { string filePath = Path.Combine(_env.ContentRootPath, "wwwroot\\images\\upload", image.FileName); if (System.IO.File.Exists(filePath)) { return("a"); } byte[] buffer = new byte[image.Length]; image.OpenReadStream().ReadAsync(buffer, 0, Convert.ToInt32(image.Length)); System.IO.File.WriteAllBytes(filePath, buffer); } return(model.Title); }
public async Task <Guid> CreatePost(CreatePostRequestModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var request = new CreatePostRequest { AuthorId = UserId, CategoriesIds = model.CategoriesIds, Description = model.Description, Title = model.Title, ImageId = model.ImageId }; var postId = await _postsManagementService.CreatePost(request); return(postId); }
public void PerformQueryTest(string quote, string market, EBuySell recommend, string price, EAccessMode access, string content, string forecast, string file) { CreatePostRequestModel model = new CreatePostRequestModel(quote, market, recommend, price, access, content, forecast, file); var actual = model.PerformQuery(); foreach (var item in typeof(CreatePostRequestModel).GetRuntimeMethods()) { var res = item.GetParameters(); if (item.Name.Equals("GetStringForecastTime") && item.GetParameters().First().ParameterType == typeof(string)) { forecast = item.Invoke(model, new object[] { forecast }) as string; break; } } var expected = new JObject { ["quote"] = quote, ["market"] = market, ["recommend"] = recommend == EBuySell.None ? string.Empty : recommend.ToString(), ["access"] = access == EAccessMode.None ? string.Empty : access.ToString(), ["forecast"] = forecast }; if (!string.IsNullOrWhiteSpace(price)) { expected["price"] = price; } if (!string.IsNullOrWhiteSpace(file)) { expected["image"] = "data:image/gif;base64," + file; } if (!string.IsNullOrWhiteSpace(content)) { expected["content"] = content; } Assert.IsTrue(JToken.DeepEquals(actual, expected)); }
public JsonResponse Execute(CreatePostRequestModel requestModel) { throw new NotImplementedException(); }