Beispiel #1
0
        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);
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
 public async Task <FieldModel> GetByIdAsync(int id) =>
 _mapper.Map <FieldModel>(await _fieldRepository.GetByIdAsync(id));