public async Task <CVDataset> GetCVById(int id, string lang = "vi") { CVDataset result = null; Models.CV cv = await _uow.CVRepository.GetFirst(filter : cv => cv.CVId == id, includeProperties : "Employee,Employee.Account"); if (cv != null) { result = _mapper.Map <CVDataset>(cv); result.Major = new Datasets.Major.MajorDataset() { MajorId = cv.MajorId.GetValueOrDefault(0), MajorName = (await _uow.TranslationRepository.GetFirst(filter: t => t.MajorId == cv.MajorId.GetValueOrDefault(0) && t.Language == lang)).Text }; IEnumerable <Section> sections = await _uow.SectionRepository.Get(filter : section => section.CVId == id, includeProperties : "SectionType"); IEnumerable <SectionField> fields = await _uow.SectionFieldRepository.Get(filter : field => field.Section.CVId == id, includeProperties : "Section"); IEnumerable <Models.Video> videos = await _uow.VideoRepository.Get(filter : video => video.Section.CVId == id, includeProperties : "Section,VideoStyle"); result.Sections = (from section in sections select new CVSectionDataset() { SectionId = section.SectionId, CVId = id, SectionTypeId = section.SectionTypeId, Text = section.Text, Title = section.DisplayTitle, Icon = section.SectionType.Image, Fields = (from field in fields where field.SectionId == section.SectionId select new CVFieldDataset() { FieldId = field.FieldId, Name = field.FieldTitle, Text = field.Text }).ToList(), Videos = (from video in videos where video.SectionId == section.SectionId select new VideoDataset() { AspectRatio = video.AspectRatio, ThumbUrl = video.ThumbUrl, VideoUrl = video.VideoUrl, CoverUrl = video.CoverUrl, VideoId = video.VideoId, VideoStyle = new VideoStyleDataset() { StyleId = video.VideoStyle.StyleId, StyleName = video.VideoStyle.StyleName } }).ToList() }).ToList(); } return(result); }
public async Task <ActionResult <CVDataset> > GetCV(int id, string lang = "vi") { CVDataset result = await _cvService.GetCVById(id, lang); if (result == null) { return(NotFound()); } return(Ok(result)); }
public async Task <IActionResult> CreateCV([FromBody] NewCVParam cv) { int userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); if (await _cvService.GetCVByName(cv.Title, userId) != null) { return(BadRequest(new { message = "CV title is existed" })); } CVDataset result = await _cvService.CreateCV(userId, cv.Title, cv.MajorId); if (result != null) { return(Created("", result)); } return(BadRequest()); }