public async Task <bool> UpdateSection(NewSectionParam section) { Section updateSection = await _uow.SectionRepository.GetById(section.SectionId); updateSection.DisplayTitle = section.Title; updateSection.Text = section.Text; _uow.SectionRepository.Update(updateSection); return(await _uow.CommitAsync() > 0); }
public async Task <CVSectionDataset> CreateSection(NewSectionParam section) { if (await _uow.SectionRepository.GetFirst(filter: s => s.CVId == section.CVId && s.SectionTypeId == section.SectionTypeId) != null) { throw new Exception("Confict"); } Section newSection = new Section() { CVId = section.CVId, SectionTypeId = section.SectionTypeId, DisplayTitle = section.Title }; if (section.Title == null) { Translation trans = await _uow.TranslationRepository.GetFirst(filter : trans => trans.SectionTypeId == section.SectionTypeId && trans.Language == "vi"); newSection.DisplayTitle = trans.Text; } if (section.Text != null && section.Text != string.Empty) { newSection.Text = section.Text; } List <CVFieldDataset> fields = section.Fields; if (fields != null && fields.Count > 0) { for (int i = 0; i < fields.Count; i++) { _uow.SectionFieldRepository.Insert(new SectionField() { FieldTitle = fields[i].Name, SectionId = newSection.SectionId, Text = fields[i].Text }); } } _uow.SectionRepository.Insert(newSection); if (await _uow.CommitAsync() > 0) { return(_mapper.Map <CVSectionDataset>(await _uow.SectionRepository.GetById(newSection.SectionId))); } return(null); }
public async Task <IActionResult> CreateSection([FromRoute] int cvId, [FromBody] NewSectionParam section) { if (cvId != section.CVId) { return(Forbid()); } try { CVSectionDataset result = await _cvService.CreateSection(section); if (result != null) { return(Created("", result)); } } catch (Exception ex) { if (ex.Message.Contains("confict")) { return(Conflict()); } } return(BadRequest()); }
public async Task <IActionResult> UpdateSection([FromRoute] int cvId, [FromRoute] int sectionId, [FromBody] NewSectionParam section) { if (cvId != section.CVId || sectionId != section.SectionId) { return(Forbid()); } if (await _cvService.GetCVSection(cvId, sectionId) == null) { return(NotFound()); } if (await _cvService.UpdateSection(section)) { return(NoContent()); } return(BadRequest()); }