public ResultHelperModel ToggleLike(LikeDto dto) { var result = new ResultHelperModel { Success = true, Message = string.Empty }; var entity = _baseRepository.Get <TweetLike>(x => x.UserProfileId == dto.UserProfileId && x.TweetId == dto.DestinationId); try { if (entity != null) { _baseRepository.Remove(entity); } else { var like = _mapper.Map <TweetLike>(dto); _baseRepository.Create(like); } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public ResultHelperModel Create(int userId, UserProfileDto dto) { var userProfile = _mapper.Map <UserProfile>(dto); userProfile.UserId = userId; userProfile.AddedDate = DateTime.Now; var result = new ResultHelperModel { Success = true, Message = string.Empty }; try { _baseRepository.Create(userProfile); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public ResultHelperModel Create(int userId, CreateTweetDto dto) { var result = new ResultHelperModel { Success = true, Message = string.Empty }; var userProfile = _baseRepository.Get <UserProfile>(x => x.UserId == userId); var tweet = _mapper.Map <Tweet>(dto); tweet.UserProfile = userProfile; tweet.AddedDate = DateTime.Now; if (!string.IsNullOrEmpty(dto.Photo)) { try { tweet.Photo = _fileUploader.Upload(dto.Photo); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; return(result); } } try { _baseRepository.Create(tweet); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; return(result); } return(result); }
public ResultHelperModel Registration(RegistrationDto dto) { var isExist = IsUserExist(dto.UserName); var result = new ResultHelperModel { Success = false, Message = null }; if (isExist) { throw new ApiException(AuthExceptionMessages.USER_ALREADY_EXIST); } var encodedPassword = PasswordHelper.EncodePassword(dto.Password); var newUser = new User { UserName = dto.UserName, Email = dto.Email, Password = encodedPassword.PasswordHash, PasswordSalt = encodedPassword.PasswordSalt, AddedDate = DateTime.Now }; try { _baseRepository.Create(newUser); _userProfileService.Create(newUser.Id, dto.UserProfile); result.Success = true; return(result); } catch (Exception ex) { throw new ApiException(ex.ToString(), ex); } }
public ResultHelperModel ToggleFollow(FollowDto dto) { var result = new ResultHelperModel { Success = true, Message = string.Empty }; if (dto.SourceId == dto.DestinationId) { result.Success = false; result.Message = CAN_NOT_FOLLOW_YOURSELF; return(result); } var entity = _baseRepository.Get <Follower>(x => x.FromUserId == dto.SourceId && x.ToUserId == dto.DestinationId); try { if (entity != null) { _baseRepository.Remove <Follower>(entity); } else { var follow = _mapper.Map <Follower>(dto); _baseRepository.Create <Follower>(follow); } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public ResultHelperModel AddComment(CreatCommentDto dto) { var result = new ResultHelperModel { Success = true, Message = string.Empty }; try { var comment = _mapper.Map <Comment>(dto); comment.AddedDate = DateTime.Now; _baseRepository.Create(comment); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public ResultHelperModel Update(int userId, UserProfileDto dto) { var userProfile = _baseRepository.Get <UserProfile>(x => x.UserId == userId); _mapper.Map(dto, userProfile); var result = new ResultHelperModel { Success = true, Message = string.Empty }; try { _baseRepository.Update(userProfile); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }