public async Task <IActionResult> Post([FromBody] AddItemGroupViewModel model)
        {
            Guid?parentId = null;

            if (model == null)
            {
                return(BadRequest());
            }

            if (model.ParentItemGroupId.HasValue)
            {
                var parentItemGroup = await _itemGroupRepo.GetAsync(model.ParentItemGroupId.Value);

                if (parentItemGroup == null)
                {
                    return(NotFound(Resources.Items.ItemResource.ParentItemGroupNotFound));
                }
                parentId = parentItemGroup.Id;
            }

            if (await _itemGroupRepo.IsExistCodeAsync(model.Code))
            {
                ModelState.AddModelError("Code", Resources.Global.Common.ThisCodeExist);
            }
            if (await _itemGroupRepo.IsExistNameAsync(model.Name))
            {
                ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist);
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetWithErrorsKey()));
            }

            var itemGroup = new ItemGroup(model.Name, model.Code, model.Note);

            if (parentId.HasValue)
            {
                itemGroup.ParentId = parentId.Value;
            }

            var affectedRows = await _itemGroupRepo.AddAsync(itemGroup);

            if (affectedRows > 0)
            {
                _itemGroupRepo.LoadReferences(itemGroup);

                var viewModel = AutoMapper.Mapper.Map <ItemGroupViewModel>(itemGroup);

                return(CreatedAtRoute("GetItemGroup", new { id = itemGroup.Number }, viewModel));
            }
            return(BadRequest());
        }