public async Task <IUseCaseResult> AddUserPlantActivityAsync(AddUserPlantActivityDto addUserPlantActivityDto, List <AddFileDto> files, string emailAddress) { // Get user details var user = await _userService.GetUserByEmailAsync(emailAddress); if (user == null) { return(UseCase.Fail(ResponseMessage.DetailsIncorrect)); } // Get Dto var userPlantActivityDto = JsonSerializer.Deserialize <UserPlantActivityDto>(addUserPlantActivityDto.UserPlantActivitySerialized, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); if (userPlantActivityDto == null) { return(UseCase.Fail(ResponseMessage.DetailsIncorrect)); } // Add files var addedFiles = await _userPlantActivityService.AddUserPlantMediaAsync(files, userPlantActivityDto.UserPlantId, user.Id); // Add activity await _userPlantActivityService.AddUserPlantActivityAsync(userPlantActivityDto, addedFiles, user.Id); return(UseCase.Success()); }
public async Task <IUseCaseResult <IEnumerable <UserPlantDto> > > GetUserPlantsAsync(string emailAddress) { var user = await _userService.GetUserByEmailAsync(emailAddress); if (user == null) { return(UseCase.Fail <IEnumerable <UserPlantDto> >(null, ResponseMessage.DetailsIncorrect)); } var userPlants = await _userPlantService.GetUserPlantsAsync(user.Id); return(UseCase.Success(userPlants)); }
public async Task <IUseCaseResult> AddUserPlantAsync(AddUserPlantDto addUserPlantDto, string emailAddress) { var user = await _userService.GetUserByEmailAsync(emailAddress); if (user == null) { return(UseCase.Fail(ResponseMessage.DetailsIncorrect)); } await _userPlantService.AddUserPlantAsync(addUserPlantDto, emailAddress); return(UseCase.Success()); }
public async Task <IUseCaseResult <UserDto> > SignIn(SignInUserDto signInUserDto) { // Get User var user = await _userService.GetUserByEmailAsync(signInUserDto.EmailAddress); if (user == null) { return(UseCase.Fail <UserDto>(null, ResponseMessage.DetailsIncorrect)); } // Create JWT (access token) var accessToken = _authenticationService.CreateAccessToken(user.EmailAddress); user.Token = accessToken.Token; return(UseCase.Success(user)); }
public async Task <IUseCaseResult <UserPlantResponseDto> > GetUserPlantAsync(string userPlantId) { // get user plant var userPlant = await _userPlantService.GetUserPlantAsync(userPlantId); if (userPlant == null) { return(UseCase.Fail <UserPlantResponseDto>(null, ResponseMessage.UserPlantNotFound)); } // get plant var plant = await _plantService.GetPlantAsync(userPlant.PlantId); if (userPlant == null) { return(UseCase.Fail <UserPlantResponseDto>(null, ResponseMessage.PlantNotFound)); } // get user var user = await _userService.GetUserByIdAsync(userPlant.UserId); if (userPlant == null) { return(UseCase.Fail <UserPlantResponseDto>(null, ResponseMessage.UserNotFound)); } // combine the data var userPlantResponseDto = new UserPlantResponseDto { Id = userPlant.Id, PlantId = userPlant.PlantId, UserId = userPlant.UserId, Nickname = userPlant.Nickname, Plant = plant, User = user }; return(UseCase.Success(userPlantResponseDto)); }
public async Task <IUseCaseResult <UserDto> > SignUp(SignUpUserDto signUpUserDto) { // Check if user exists var user = await _userService.GetUserByEmailAsync(signUpUserDto.EmailAddress); if (user != null) { return(UseCase.Fail <UserDto>(null, ResponseMessage.EmailExists)); } // Hash Password signUpUserDto.Password = _authenticationService.CreatePasswordHash(signUpUserDto.Password); // Create User var newUser = await _userService.CreateUserAsync(signUpUserDto); // Create JWT (access token) var accessToken = _authenticationService.CreateAccessToken(newUser.EmailAddress); newUser.Token = accessToken.Token; return(UseCase.Success(newUser)); }