public void DeletePost() { AutoMapperDataConfig.RegisterMappings(); PublisherService publisherService = new PublisherService(new PostRepository(), new TagRepository()); int maxId = publisherService.GetAllPosts().Max(x => x.Id); var postDto = new PostDto() { Id = maxId }; publisherService.Delete(postDto); var postDeleted = publisherService.GetById(maxId); Assert.IsNull(postDeleted); }
public void CreatePost() { AutoMapperDataConfig.RegisterMappings(); PublisherService publisherService = new PublisherService(new PostRepository(), new TagRepository()); var postDto = new PostDto() { Body = "Body", Title = "Title", User = new UserDto() { Login = "******" }, Tags = new List<string> { "Deus", "Bíblia", "Deus vivo" } }; publisherService.Publish(postDto); }
public record Request(PostDto Post) : IRequest <Response>;
public async Task <Post> UpdatePostAsync(PostDto postDto) { return(await _context.UpdatePostAsync(postDto)); }
public async Task <IActionResult> CreatePost([FromBody] PostDto post) { var result = await _postService.CreatePost(post); return(new OkObjectResult(ApiResponse.Create(result))); }
public IHttpActionResult EditPost(int id, PostDto postDto) { return(Put(userId => Repository.PostRepository.UpdatePost(id, userId, postDto))); }
public Task <int> CreateAsync(PostDto post) { return(Task.Run(() => { return Create(post); })); }
public async Task <ServiceResult <string> > UpdatePostAsync([Required] int id, [FromBody] PostDto dto) { return(await _blogService.UpdatePostAsync(id, dto)); }
public async Task <ActionResult <PostDto> > UpdatePost([FromBody] PostDto post) { var response = await mediator.Send(new UpdatePost.Command(post), CancellationToken.None); return(ToActionResult(response)); }
public async Task <IActionResult> Create([FromBody] PostDto post) { post = await _postService.Create(post); return(Created("api/Post", post)); }
public JsonResult Delete([FromBody] PostDto postDto) { _context.DeletePost(postDto.id); return(new JsonResult("correct")); }
public async Task AddPostAsync(PostDto post) { await _mongoRepository.InsertOneAsync(_mapper.Map <PostDto, Post>(post)); }
protected async Task <CommentDto> CreateAndGetRandomComment(PostDto post, UserDto user) { var responseComment = await CreateNewComment(post.Id); return(await GetCommentAsync(responseComment.Headers.Location.ToString())); }
public void Edit(PostDto request) { context.PostRepository.Update(Mapper.Map <PostDto, Post>(request)); context.Commit(); }
public void Add(PostDto request) { context.PostRepository.Add(Mapper.Map <PostDto, Post>(request)); context.Commit(); }
public async Task <HttpStatusCode> addPost(PostDto postDto) { Post post = _mapper.Map <Post>(postDto); return(await _post.addPost(post)); }
/// <summary> /// 同步Post到Server /// </summary> public static void UpdatePostToServer(int nodeId) { PostFactory m_PostFactory = new PostFactory(); IPostService m_PostService = m_PostFactory.GetPostService(); ConfigHelper m_ConfigHelper = new ConfigHelper(); if (string.IsNullOrEmpty(m_ConfigHelper.PostApiUrl)) { return; } Dictionary <string, string> conditions = new Dictionary <string, string>(); conditions.Add("NeedUpdate", "true"); conditions.Add("NodeId", nodeId.ToString()); IList <PostVO> list = m_PostService.GetPostList(conditions); if (list != null && list.Count > 0) { foreach (PostVO vo in list) { try { PostVO postVO = m_PostService.GetPostById(vo.PostId); if (postVO.IsUpdatingToServer) { continue; } PostDto dto = new PostDto(vo); //狀態為刪除 if (dto.Flag == 0) { vo.IsUpdatingToServer = true; m_PostService.UpdatePost(vo); if (dto.ServerId > 0) { //有serverId就去server刪除 string url = m_ConfigHelper.PostApiUrl + "/" + dto.ServerId.ToString(); WebRequest request = ApiUtil.Post(url, "DELETE", ""); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Gone || response.StatusCode == HttpStatusCode.NoContent) { vo.NeedUpdate = false; vo.IsUpdatingToServer = false; m_PostService.UpdatePost(vo); } } } else { //沒有serverId就直接標記已更新 vo.NeedUpdate = false; vo.IsUpdatingToServer = false; m_PostService.UpdatePost(vo); } } else { vo.IsUpdatingToServer = true; m_PostService.UpdatePost(vo); WebRequest request = ApiUtil.Post <PostDto>(m_ConfigHelper.PostApiUrl, "POST", dto); string responseInfo = string.Empty; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode == HttpStatusCode.Created) { using (Stream stream = response.GetResponseStream()) { responseInfo = (new StreamReader(stream)).ReadToEnd().Trim(); PostDto newPostDto = JsonConvert.DeserializeObject <PostDto>(responseInfo); vo.IsUpdatingToServer = false; vo.NeedUpdate = false; vo.ServerId = newPostDto.PostId; m_PostService.UpdatePost(vo); } } } } } catch (Exception ex) { vo.IsUpdatingToServer = false; m_PostService.UpdatePost(vo); string error = ex.ToString(); } } } }
public async Task <ServiceResult <string> > InsertPostAsync([FromBody] PostDto dto) { return(await _blogService.InsertPostAsync(dto)); }
public override Task <ApiResult <PostDto> > Create(PostDto dto, CancellationToken cancellationToken) { return(base.Create(dto, cancellationToken)); }
public IActionResult Post([FromBody] PostDto dto, [FromServices] ICreatePostCommand command) { dto.UserId = actor.Id; executor.ExecuteCommand(command, dto); return(StatusCode(StatusCodes.Status201Created)); }
public override Task <ApiResult <PostDto> > Update(Guid id, PostDto dto, CancellationToken cancellationToken) { return(base.Update(id, dto, cancellationToken)); }
protected override async Task OnInitializedAsync() { Posts = await _postService.GetPostList(); FeaturedPost = await _postService.GetFeaturedPost(); }
public PostTableModel(PostDto post) { this.Id = post.Id; this.Title = post.Title; this.Content = post.Content; }
public IHttpActionResult AddPost(PostDto postDto) { return(Post(userId => Repository.PostRepository.AddPost(userId, postDto))); }
public JsonResult getThongKe(DataDateDto data) { var stID = Guid.Parse(data.StoreID); DateTime date = DateTime.ParseExact(data.Month + "/" + data.Year, "M/yyyy", CultureInfo.InvariantCulture); var store = db.Stores.SingleOrDefault(n => n.StoreID == stID); if (store == null) { return(null); } var invoices = db.Invoices.Where(n => n.StoreID == stID && n.OrderDate.Value.Month == date.Month && n.OrderDate.Value.Year == date.Year) .GroupBy(n => n.OrderDate.Value.Day) .Select(n => new { ngay = n.Key, sodondat = n.Count() }) .ToList(); List <InvoiceDto> lstIV = new List <InvoiceDto>(); foreach (var detail in invoices) { InvoiceDto ivDto = new InvoiceDto { OrderDate = detail.ngay.ToString(), NumberInvoice = detail.sodondat }; lstIV.Add(ivDto); } List <PostDto> lstpost = new List <PostDto>(); var posts = db.Posts.Where(n => n.StoreID == stID && n.PostTime.Value.Month == date.Month && n.PostTime.Value.Year == date.Year) .GroupBy(n => n.PostTime.Value.Day) .Select(n => new { ngay = n.Key, sobaiviet = n.Count() }) .ToList(); foreach (var pt in posts) { PostDto cmt = new PostDto { PostTime = pt.ngay.ToString(), NumberPost = pt.sobaiviet }; lstpost.Add(cmt); } var invoiceDoanhThu = db.Invoices.Where(n => n.StoreID == stID && n.OrderDate.Value.Month == date.Month && n.OrderDate.Value.Year == date.Year) .GroupBy(n => new { Day = n.OrderDate.Value.Day, }) .Select(n => new RevenueDTo { Day = n.Key.Day, NumberInvoice = n.Count(), Money = n.Sum(i => i.TotalPrice).Value }) .ToList(); //var NumberFood = db.InvoiceDetails.Where(m => m.InvoiceID == n.Key.InvoiceID) // .GroupBy(m => m.InvoiceID) // .Select(m => m.Sum(i => i.NumberFood)) // .FirstOrDefault().Value; ThongKeDto tk = new ThongKeDto() { Invoices = lstIV, Posts = lstpost, Revenues = invoiceDoanhThu }; return(Json(tk, JsonRequestBehavior.AllowGet)); }
public void Post([FromBody] PostDto dto, [FromServices] ICreatePostCommand command) { _executor.ExecuteCommand(command, dto); }
public IActionResult Put(int id, [FromBody] PostDto dto, [FromServices] IUpdatePostCommand command) { dto.Id = id; executor.ExecuteCommand(command, dto); return(StatusCode(StatusCodes.Status204NoContent)); }
public async Task <Post> DeletePostAsync(PostDto postDto) { return(await _context.DeletePostAsync(postDto)); }
public static PostDto ApplyAuthorName(this PostDto post, User author) { post.AuthorName = author.Name; return(post); }
public void UpdatePost() { AutoMapperDataConfig.RegisterMappings(); PublisherService publisherService = new PublisherService(new PostRepository(), new TagRepository()); var postDto = new PostDto() { Id = 1, Body = "Body 1", Title = "Title 1", User = new UserDto() { Login = "******" } }; publisherService.Edit(postDto); var postUpdated = publisherService.GetById(1); Assert.IsNotNull(postUpdated); Assert.AreEqual(postDto.Body, postUpdated.Body); Assert.AreEqual(postDto.Title, postUpdated.Title); }
public ApiResponse(PostDto postDto) { this.postDto = postDto; }
public void CreatePost(PostDto post) { throw new NotImplementedException(); }
public PostViewModel Map(PostDto postDto) => _mapper.Map <PostViewModel>(postDto);