public async Task <UserFullInfoServiceModel> GetFullInfoById(Guid id) { UserFullInfoDTO userInfo = await _uow.Users.GetFullUserInfo(id); UserFullInfoServiceModel userFullInfo = _mapper.Map <UserFullInfoDTO, UserFullInfoServiceModel>(userInfo); return(userFullInfo); }
public async Task <CVServiceModel> AddAsync(CVCreationServiceModel cvServiceModel) { Guid?userId = cvServiceModel.UserId; var educationsToAdd = _mapper.Map < ICollection <EducationWithDetailsServiceModel>, ICollection <EducationWithDetailsDTO> > (cvServiceModel.Educations); if (userId == null) { UserFullInfoDTO userToAdd = _mapper.Map < UserCreationServiceModel, UserFullInfoDTO> (cvServiceModel.User); userToAdd.Educations = educationsToAdd; var createdUser = await _uow.Users.AddAsync(userToAdd); userId = createdUser.Id; cvServiceModel.UserId = userId; } else // check if user has educations { var addedEducations = await _uow.Users.AddEducationsNoExistAsync(educationsToAdd, (Guid)userId); educationsToAdd = _mapper.Map <ICollection <Education>, ICollection <EducationWithDetailsDTO> >(addedEducations); } CVCreationDTO cv = _mapper.Map <CVCreationServiceModel, CVCreationDTO>(cvServiceModel); CVDTO createdCV = await _uow.CVs.AddAsync(cv); createdCV.Educations = educationsToAdd; await _uow.CVs.LinkUserToCV(createdCV.Id, (Guid)userId); CVServiceModel result = _mapper.Map <CVDTO, CVServiceModel>(createdCV); return(result); }
public async Task <UserFullInfoDTO> GetFullUserInfo(Guid id) { IQueryable <UserFullInfoDTO> query = _context.Users.AsQueryable() .Include(u => u.Educations) .Include(u => u.City) .Where(u => u.Id == id) .Select(u => new UserFullInfoDTO() { Id = u.Id, Email = u.Email, Phone = u.PhoneNumber, FirstName = u.FirstName, SecondName = u.SecondName, City = new CityNameDTO() { Id = u.City.Id, Name = u.City.Name }, Educations = _mapper.Map <ICollection <Education>, ICollection <EducationWithDetailsDTO> >(u.Educations) }); UserFullInfoDTO user = await query.FirstOrDefaultAsync(); Task <List <CompanyNameDTO> > companies = _context.Users.AsQueryable() .Include(u => u.UserCompanies) .SelectMany(a => a.UserCompanies) .Where(a => a.UserId == id) .Select(c => new CompanyNameDTO() { Id = c.CompanyId, Name = c.Company.Name }).ToListAsync(); user.Companies = companies.Result; return(user); }
public async Task <UserFullInfoDTO> AddAsync(UserFullInfoDTO user) { var result = await AddAsync(_mapper.Map <UserFullInfoDTO, User>(user)); return(_mapper.Map <User, UserFullInfoDTO>(result)); }