public async Task <IActionResult> Create([FromBody] UserSaveDto resourceSave) { _auditTrailRepo.User = User; var activity = Validator.GenerateActivity(resourceSave, TransactionType.ADD); var validator = await _validatorSaving.Validate(resourceSave); if (validator.HasError) { await _auditTrailRepo.SaveFailedTrail(new AuditTrailFailedSaveDto() { Action = TransactionType.ADD, Activity = activity, ErrorMessage = validator.Message }); return(BadRequest(validator.Message)); } var user = _mapper.Map <User>(resourceSave); _crudPattern.Create(user); if (!await _crudPattern.SaveChanges()) { return(BadRequest("Nothing has been Saved!")); } await _auditTrailRepo.SaveSuccessTrail(new AuditTrailSuccessSaveDto() { Action = TransactionType.ADD, Activity = activity }); return(StatusCode(201)); }
public async Task <ErrorValidator> Validate(UserSaveDto resourceSave) { if (await isEmployeeAlreadyExisted(resourceSave.EmployeeId)) { return(new ErrorValidator("Employee Selected Already has an account")); } if (await isUserNameTaken(resourceSave.UserName)) { return(new ErrorValidator("Username Already Taken")); } if (isUserHasWhiteSpaces(resourceSave.UserName)) { return(new ErrorValidator("Username Invalid please remove spaces")); } return(new ErrorValidator()); }
public Task <ErrorValidator> Validate(User entity, UserSaveDto resourceSave) { throw new NotImplementedException(); }