public async Task <IActionResult> Put(long id, [FromBody] EditCostCenterViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (id != model.Id)
            {
                return(BadRequest());
            }

            var costcenter = await _costCenterRepo.GetAsync(id);

            if (costcenter == null)
            {
                return(NotFound(Resources.CostCenters.CostCenterResource.CostCenterNotFound));
            }

            Guid?parentId = null;

            if (model.ParentCostCenterId.HasValue)
            {
                var parentCostCenter = await _costCenterRepo.GetAsync(model.ParentCostCenterId.Value);

                if (parentCostCenter == null)
                {
                    return(NotFound(Resources.CostCenters.CostCenterResource.ParentCostCenterNotFound));
                }
                parentId = parentCostCenter.Id;
            }

            if (await _costCenterRepo.IsExistNameAsync(costcenter.Id, model.Name))
            {
                ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist);
                return(BadRequest(ModelState.GetWithErrorsKey()));
            }

            costcenter.ParentId = parentId;
            costcenter.Code     = model.Code;
            costcenter.Name     = model.Name;
            costcenter.Note     = model.Note;

            var affectedRows = await _costCenterRepo.EditAsync(costcenter);

            if (affectedRows > 0)
            {
                var viewModel = AutoMapper.Mapper.Map <CostCenterViewModel>(costcenter);

                return(Ok(viewModel));
            }
            return(BadRequest());
        }