Exemplo n.º 1
0
        public async Task <FieldGroupViewModel> RemoveFieldFromGroup(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. ");
            }

            foreach (var item in request.FieldIds)
            {
                if (group.FieldId.Any(x => x == item))
                {
                    group.FieldId.Remove(item);
                }
            }
            group.FieldId.Distinct();
            await fieldGroupRepository.UpdateAsync(group, group.Id);

            return(mapper.Map <FieldGroupViewModel>(group));
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> RemoveFieldFromGroup(AddFieldToGroupRequest request)
        {
            var data = await fieldService.RemoveFieldFromGroup(request);

            return(Ok(new ApiOkResponse(data)));
        }