コード例 #1
0
        public IActionResult CreatePost(CreatePostRequestModel newPost)
        {
            var user = _users.GetById(newPost.UserId);

            _posts.CreatePost(newPost, user);
            return(RedirectToAction("PostsPage"));
        }
コード例 #2
0
 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);
     });
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public IActionResult CreatePost(CreatePostRequestModel newPost)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreatePostPage", newPost));
            }

            _posts.CreatePost(newPost);
            return(RedirectToAction("PostsPage"));
        }
コード例 #6
0
 public void CreatePost(CreatePostRequestModel postModel)
 {
     _context.Posts.Add(new Post
     {
         ImageUrl = postModel.ImageUrl,
         Message  = postModel.Message,
         PostedAt = DateTime.Now,
         UserId   = postModel.UserId,
     });
     _context.SaveChanges();
 }
コード例 #7
0
 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();
 }
コード例 #8
0
        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);
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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));
        }
コード例 #13
0
 public JsonResponse Execute(CreatePostRequestModel requestModel)
  {
      throw new NotImplementedException();
  }