public virtual Profile CreateProfile(Profile profile) { if (!String.IsNullOrEmpty(profile.FriendlyName)) { if (_profileRepository.CheckIfFriendlyNameExists(profile.FriendlyName, profile.Id)) { throw new KatushaFriendlyNameExistsException(profile); } } if (!(profile.Gender == (byte)Sex.Male || profile.Gender == (byte)Sex.Female)) { throw new KatushaGenderNotExistsException(profile); } _profileRepository.Add(profile); _profileRepository.Save(); var user = _userRepository.SingleAttached(p => p.Id == profile.UserId); user.Gender = profile.Gender; _userRepository.FullUpdate(user); _katushaGlobalCache.Delete("U:" + user.UserName); UpdateRavenProfile(profile.Id); _notificationService.ProfileCreated(profile); return(profile); }
public bool DeletePhoto(long profileId, Guid photoGuid) { var photos = _photoRepository.Query(p => p.ProfileId == profileId, null, false); if (photos.Count > 1) { var entity = _photoRepository.SingleAttached(p => p.Guid == photoGuid && p.ProfileId == profileId); return(_DeletePhoto(entity)); } var profile = _profileRepository.SingleAttached(p => p.Id == profileId); var firstOrDefault = photos.FirstOrDefault(); if (firstOrDefault != null) { profile.ProfilePhotoGuid = firstOrDefault.Guid; _profileRepository.Save(); } throw new Exception("Only one photo remaining. Cannot delete."); }