public virtual Result <TReadDto> Create(TCreateDto dto, string createdBy) { AuthorizeResourceOperationAsync(ResourceCollectionsCore.CRUD.Operations.Create).Wait(); var objectValidationErrors = ValidationService.ValidateObject(dto); if (objectValidationErrors.Any()) { return(Result.ObjectValidationFail <TReadDto>(objectValidationErrors)); } var bo = Mapper.Map <TEntity>(dto); Repository.Add(bo, createdBy); var result = UnitOfWork.Complete(); if (result.IsFailure) { switch (result.ErrorType) { case ErrorType.ObjectValidationFailed: return(Result.ObjectValidationFail <TReadDto>(result.ObjectValidationErrors)); default: throw new ArgumentException(); } } var readDto = Mapper.Map <TReadDto>(bo); if (HubContext != null) { HubContext.CreatedAsync(readDto).Wait(); } return(Result.Ok(readDto)); }
public virtual Result <TReadDto> Create(TCreateDto dto, string createdBy) { var validatableObject = dto as IObjectValidatable; if (validatableObject != null) { var objectValidationErrors = validatableObject.Validate().ToList(); if (objectValidationErrors.Any()) { return(Result.ObjectValidationFail <TReadDto>(objectValidationErrors)); } } var bo = Mapper.Map <TEntity>(dto); var result = DomainService.Create(bo, createdBy); if (result.IsFailure) { switch (result.ErrorType) { case ErrorType.ObjectValidationFailed: return(Result.ObjectValidationFail <TReadDto>(result.ObjectValidationErrors)); default: throw new ArgumentException(); } } var readDto = Mapper.Map <TReadDto>(bo); if (HubContext != null) { HubContext.CreatedAsync(readDto).Wait(); } return(Result.Ok(readDto)); }