async Task <ServiceResponse <List <CompanyUserDto> > > ICompanyUserService.CreateCompanyUser(CreateCompanyUserDto companyUserDto)
        {
            ServiceResponse <List <CompanyUserDto> > response = new ServiceResponse <List <CompanyUserDto> >();
            Company company = await _context.Companies.FirstOrDefaultAsync(a => a.companyId == companyUserDto.companyId);

            CompanyUser user = await _context.CompanyUsers.FirstOrDefaultAsync(a => a.email == companyUserDto.email);

            if (user != null)
            {
                response.Success = false;
                response.Message = "This email already has an account";
                return(response);
            }

            if (company == null)
            {
                response.Success = false;
                response.Message = "The company entered does not exist";
                return(response);
            }

            string      finalString  = new IDGenerator.IDGenerator().generate();
            String      lastLoggedIn = DateTime.Now.ToString();
            CompanyUser newUser      = new CompanyUser(finalString, company.companyName, companyUserDto.companyId, companyUserDto.email, lastLoggedIn, true);
            await _context.CompanyUsers.AddAsync(newUser);

            await _context.SaveChangesAsync();

            List <CompanyUserDto> newList = await _context.CompanyUsers.Select(a => new CompanyUserDto(a.companyUserId, a.companyId, a.companyName, a.email, a.lastLoggedIn, a.isActive)).ToListAsync();

            response.Data = newList;
            return(response);
        }
        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);
        }
Ejemplo n.º 3
0
        async Task <ServiceResponse <List <GetCompanyPostAdminDto> > > ICompanyPostService.CreateCompanyPost(CreateCompanyPostDto companyPostDto)
        {
            ServiceResponse <List <GetCompanyPostAdminDto> > response = new ServiceResponse <List <GetCompanyPostAdminDto> >();
            Company companyOfPost = await _context.Companies.FirstOrDefaultAsync(a => a.companyId == companyPostDto.companyId);

            CompanyUser companyUserOfPost = await _context.CompanyUsers.FirstOrDefaultAsync(a => a.companyUserId == companyPostDto.companyUserId);

            if (companyOfPost == null)
            {
                response.Success = false;
                response.Message = "The company for this post does not exist";
                return(response);
            }
            if (companyUserOfPost == null)
            {
                response.Success = false;
                response.Message = "The poster of the post does not exist";
                return(response);
            }


            string      finalString = new IDGenerator.IDGenerator().generate();
            string      lastUpdated = DateTime.Now.ToString();
            CompanyPost newPost     = new CompanyPost(finalString, companyPostDto.companyId, companyPostDto.companyUserId, companyOfPost.companyName, companyPostDto.postTitle, companyPostDto.postSubTitle, companyPostDto.postDescription, companyPostDto.videoUrl, companyPostDto.links, lastUpdated, companyPostDto.approvedBy, companyPostDto.validTill, true);
            await _context.CompanyPosts.AddAsync(newPost);

            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);
        }
        async Task <ServiceResponse <List <GetCompanyAdminDto> > > ICompanyService.CreateCompany(CreateCompanyDto companyDto)
        {
            ServiceResponse <List <GetCompanyAdminDto> > response = new ServiceResponse <List <GetCompanyAdminDto> >();

            if (await _context.Companies.FirstOrDefaultAsync(a => a.companyName == companyDto.companyName) != null)
            {
                response.Success = false;
                response.Message = "This company already has an account";
                return(response);
            }

            string finalString = new IDGenerator.IDGenerator().generate();

            Company newCompany = new Company(finalString, companyDto.companyName, companyDto.companyTier, companyDto.companyDescription, true);
            await _context.Companies.AddAsync(newCompany);

            await _context.SaveChangesAsync();

            List <Company> newCompanyList = await _context.Companies.ToListAsync();

            response.Data = newCompanyList.Select(a => new GetCompanyAdminDto(a.companyId, a.companyName, a.companyTier, a.companyDescription, a.isActive)).ToList();;
            return(response);
        }