public async Task <int> Handle(UpdateFunctionalObjectCommand request, CancellationToken cancellationToken)
        {
            _unitOfWork.BeginTransaction();

            try
            {
                var exists = await _functionalObjectRepository.IsFunctionalObjectExistsAsync(request.Name, request.Id);

                if (exists)
                {
                    throw new AtlasBusinessException($"A functional object with the name {request.Name} already exists.");
                }

                var functionalObject = ConvertToFunctionalObject(null, request);
                if (functionalObject != null)
                {
                    functionalObject.Id = request.Id;
                    var functionalObjectId = await _functionalObjectRepository.UpdateFunctionalObject(functionalObject);

                    _unitOfWork.Commit();

                    _logger.LogInformation("Functional object {Atlas_FunctionalObjectName} has been updated.", request.Name);

                    return(functionalObjectId);
                }
                else
                {
                    throw new AtlasBusinessException($"Invalid Request.");
                }
            }
            catch
            {
                _unitOfWork.Rollback();
                throw;
            }
        }
 private static FunctionalObject ConvertToFunctionalObject(CreateFunctionalObjectCommand createCommand, UpdateFunctionalObjectCommand updateCommand)
 {
     if (createCommand != null && updateCommand == null)
     {
         return(new FunctionalObject()
         {
             Name = createCommand.Name,
             Tables = new List <ApplicationTable>(createCommand.Keys.Select((key, index) => new ApplicationTable()
             {
                 TableId = key.TableId,
                 Fields = new List <ApplicationField>(key.FieldIds.Select((id) => new ApplicationField()
                 {
                     FieldId = id
                 }))
             }))
         });
     }
     else if (createCommand == null && updateCommand != null)
     {
         return(new FunctionalObject()
         {
             Name = updateCommand.Name,
             Tables = new List <ApplicationTable>(updateCommand.Keys.Select((key, index) => new ApplicationTable()
             {
                 TableId = key.TableId,
                 Fields = new List <ApplicationField>(key.FieldIds.Select((id) => new ApplicationField()
                 {
                     FieldId = id
                 }))
             }))
         });
     }
     return(null);
 }