async public Task <IActionResult> createRequest(CreateCompanyPostRequestDto dto) { ServiceResponse <List <GetCompanyPostRequestDto> > response = await _companyPostRequestService.CreateCompanyPostRequest(dto); if (response.Success) { return(Ok(response.Data)); } else { return(NotFound(response.Message)); } }
async Task <ServiceResponse <List <GetCompanyPostRequestDto> > > ICompanyPostRequestService.CreateCompanyPostRequest(CreateCompanyPostRequestDto toCreate) { ServiceResponse <List <GetCompanyPostRequestDto> > response = new ServiceResponse <List <GetCompanyPostRequestDto> >(); Company comp = await _context.Companies.FirstOrDefaultAsync(a => a.companyId == toCreate.companyId); CompanyUser user = await _context.CompanyUsers.FirstOrDefaultAsync(a => a.companyUserId == toCreate.companyUserId); if (comp == null) { response.Success = false; response.Message = "The company approving the request does not exist"; return(response); } if (user == null) { response.Success = false; response.Message = "The company user creating this does not exist"; return(response); } string finalString = new IDGenerator.IDGenerator().generate(); string lastUpdated = new DateTime().ToString(); CompanyPostRequest req = new CompanyPostRequest(finalString, toCreate.companyId, toCreate.companyUserId, comp.companyName, toCreate.postTitle, toCreate.postSubTitle, toCreate.postDescription, toCreate.videoUrl, toCreate.links, toCreate.validTill, "pending", null); _context.CompanyPostRequests.Add(req); await _context.SaveChangesAsync(); List <GetCompanyPostRequestDto> data = await _context.CompanyPostRequests.Select(a => new GetCompanyPostRequestDto(a)).ToListAsync(); response.Data = data; return(response); }