public async Task <SaveInformationAssetResponse> Handle(IInformationAsset message)
        {
            // Build the Domain.Asset model based on the data supplied
            var newModel = BuildAssetModel(message);

            // Validate the new Asset conforms to the Domain rules
            var validationResult = newModel.Validate();

            // Prep response
            var response = new SaveInformationAssetResponse
            {
                ValidationResult = validationResult
            };

            // If the model is valid then attempt to save it
            if (validationResult.IsValid)
            {
                try
                {
                    var repo = _unitOfWork.GetRepository <Asset>();

                    if (message.AssetId > 0)
                    {
                        await repo.Edit(newModel);
                    }
                    else
                    {
                        await repo.Create(newModel);
                    }

                    await _unitOfWork.Save();

                    response.Asset = newModel;
                }
                catch (Exception ex)
                {
                    // Failed to save the asset so copy error to response so clients can see what has gone wrong.
                    response.InnerException = ex;
                    response.ResponseType   = ResponseTypes.Failure;
                    response.OutputMessage  = "Failed to save the asset. See exception for details.";
                }
            }

            return(response);
        }
Example #2
0
 public virtual void Insert(TEntity entity)
 {
     _dataRepository.Insert(entity);
     unitOfWork.Save();
 }