public async Task <FieldViewModel> GetFieldById(string fieldId) { var field = await fieldRepository.GetByIdAsync(ObjectId.Parse(fieldId)); if (field != null) { return(mapper.Map <FieldViewModel>(field)); } return(null); }
public async Task <FieldGroupViewModel> AddFieldToGroup(AddFieldToGroupRequest request) { var group = await fieldGroupRepository.GetByIdAsync(ObjectId.Parse(request.GroupId)); if (group == null) { throw new Exception("Không tìm thấy nhóm lĩnh vực. "); } group.GroupName = request.GroupName; group.FieldId.Clear(); foreach (var fieldId in request.FieldIds) { var field = await fieldRepository.GetByIdAsync(ObjectId.Parse(fieldId)); if (field != null) { group.FieldId.Add(fieldId); } } await fieldGroupRepository.UpdateAsync(group, group.Id); return(mapper.Map <FieldGroupViewModel>(group)); }
public async Task <FieldModel> GetByIdAsync(int id) => _mapper.Map <FieldModel>(await _fieldRepository.GetByIdAsync(id));