public void update(UpdateCompanyPostDto update) { this.approvedBy = update.approvedBy; this.lastUpdated = DateTime.Now.ToString(); this.postDescription = update.postDescription; this.postTitle = update.postTitle; this.postSubTitle = update.postSubTitle; this.videoUrl = update.videoUrl; this.validTill = update.validTill; this.links = update.links; }
async public Task <IActionResult> updateCompanyPost(UpdateCompanyPostDto companyPostDto) { ServiceResponse <List <GetCompanyPostAdminDto> > response = await _companyPostService.UpdateCompanyPost(companyPostDto); if (response.Success) { return(Ok(response.Data)); } else { return(NotFound(response.Message)); } }
async Task <ServiceResponse <List <GetCompanyPostAdminDto> > > ICompanyPostService.UpdateCompanyPost(UpdateCompanyPostDto companyPostDto) { ServiceResponse <List <GetCompanyPostAdminDto> > response = new ServiceResponse <List <GetCompanyPostAdminDto> >(); CompanyPost post = await _context.CompanyPosts.FirstOrDefaultAsync(a => a.companyPostId == companyPostDto.companyPostId); if (post == null) { response.Success = false; response.Message = "The post you want to update not exist"; return(response); } post.update(companyPostDto); _context.CompanyPosts.Update(post); await _context.SaveChangesAsync(); List <GetCompanyPostAdminDto> postList = await _context.CompanyPosts.Select(a => new GetCompanyPostAdminDto(a.companyPostId, a.companyUserId, a.companyId, a.companyName, a.postTitle, a.postSubTitle, a.postDescription, a.videoUrl, a.links, a.lastUpdated, a.approvedBy, a.validTill, a.isActive)).ToListAsync(); response.Data = postList; return(response); }