public ServiceResult SaveProfile(GreenWerx.Models.Membership.ProfileMember p) { if (p == null) { return(ServiceResponse.Error("Invalid form sent to server.")); } if (_profileMemberManager == null) { _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); } var res = _profileMemberManager.Get(p.UUID); if (res.Code != 200) { if (string.IsNullOrWhiteSpace(p.CreatedBy)) { p.UUID = CurrentUser.UUID; } return(_profileMemberManager.Save(p)); } GreenWerx.Models.Membership.ProfileMember dbProfile = (ProfileMember)res.Result; return(_profileMemberManager.Update(p)); }
public ServiceResult GetUserProfileBy(string profileUUID) { if (_profileMemberManager == null) { _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); } return(_profileMemberManager.Get(profileUUID)); //.GetProfile(CurrentUser.UUID, CurrentUser.AccountUUID); }
public ServiceResult SaveProfile(GreenWerx.Models.Membership.Profile p) { if (p == null) { return(ServiceResponse.Error("Invalid form sent to server.")); } ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); if (_profileMemberManager == null) { _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); } var dbProfile = profileManager.Get(p.UUID); if (dbProfile == null) { if (string.IsNullOrWhiteSpace(p.CreatedBy)) { p.UUID = CurrentUser.UUID; } p.Private = true; var res = profileManager.InsertProfile(p); if (res.Code != 200) { return(ServiceResponse.Error("Failed to create profile.")); } foreach (var profileMember in p.Members) { profileMember.CreatedBy = CurrentUser.UUID; profileMember.DateCreated = DateTime.UtcNow; profileMember.Private = true; profileMember.ProfileUUID = p.UUID; _profileMemberManager.Save(profileMember); } profileManager.UpdateProfile(p);//this will update the cache fields return(res); } foreach (var profileMember in p.Members) { _profileMemberManager.Update(profileMember); } return(profileManager.UpdateProfile(p)); }
public ServiceResult DeleteProfile(string profileUUID) { if (_profileMemberManager == null) { _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); } var p = _profileMemberManager.Get(profileUUID); if (p.Code != 200) { return(p); } _profileMemberManager.Delete((ProfileMember)p.Result, true); // purges return(ServiceResponse.OK("")); }
public ServiceResult SearchUsersReturnProfiles() { DataFilter filter = this.GetFilter(Request); ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); var profiles = profileManager.GetUserProfiles(CurrentUser.AccountUUID, ref filter); LocationManager locationManager = new LocationManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); UserManager userManager = new UserManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); profiles = profiles.Select(s => new { Name = s.Name, UUID = s.UUID, UUIDType = s.UUIDType, Image = s.Image, Active = s.Active, Description = s.Description, Members = string.IsNullOrWhiteSpace(s.MembersCache) ? _profileMemberManager.GetProfileMembers(s.UUID, s.AccountUUID, ref filter) : JsonConvert.DeserializeObject <List <ProfileMember> >(s.MembersCache), User = string.IsNullOrWhiteSpace(s.UserCache) ? userManager.Get(s.UserUUID) : JsonConvert.DeserializeObject <User>(s.UserCache), LocationDetail = string.IsNullOrWhiteSpace(s.LocationDetailCache) ? locationManager.Get(s.LocationUUID) : JsonConvert.DeserializeObject <Location>(s.LocationDetailCache), }).Cast <dynamic>(); return(ServiceResponse.OK("", profiles, filter.TotalRecordCount)); }
public ServiceResult SetActiveProfileImageFromAttribute(string attributeUUID) { AttributeManager atm = new AttributeManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); var res = atm.Get(attributeUUID); if (res.Code != 200) { return(res); } var attribute = res.Result as TMG.Attribute; if (attribute == null) { return(ServiceResponse.Error("Attribute was not found.")); } if (attribute.ValueType.EqualsIgnoreCase("ImagePath") == false) { return(ServiceResponse.Error("Attribute is not an image path type.")); } if (_profileMemberManager == null) { _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); } var profile = _profileMemberManager.GetMemberProfile(CurrentUser.UUID, CurrentUser.AccountUUID); if (profile == null) { return(ServiceResponse.Error("ProfileMember was not found.")); } profile.Image = attribute.Image; return(ServiceResponse.OK("", profile.Image)); }
[System.Web.Http.Route("api/Profiles")] // was AllProfiles public ServiceResult GetAllUserProfiles() { ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); UserManager userManager = new UserManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); LocationManager locationManager = new LocationManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); List <Profile> tmp = new List <Profile>(); DataFilter filter = this.GetFilter(Request); if (CurrentUser == null) //not logged in. { tmp = profileManager.GetPublicProfiles(ref filter); } else { tmp = profileManager.GetAllProfiles(ref filter); } if (tmp == null) { return(ServiceResponse.OK("", new List <Profile>())); } List <dynamic> profiles = tmp.Cast <dynamic>().ToList(); //profileManager.GetAllProfiles().Cast<dynamic>().ToList(); profiles = profiles.Filter(ref filter); var defaultFilter = new DataFilter(); // todo add profile Members? or rename profileLogs to profileMembers? so you can map multiple users to one profile // if profileLogs remember to sort by sortOrder _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); profiles = profiles.Select(s => new { Name = s.Name, UUID = s.UUID, AccountUUID = s.AccountUUID, UUIDType = s.UUIDType, Image = s.Image, NSFW = s.NSFW, // Email = s.Email, Active = s.Active, Description = s.Description, Members = string.IsNullOrWhiteSpace(s.MembersCache) ? _profileMemberManager.GetProfileMembers(s.UUID, s.AccountUUID, ref filter) : JsonConvert.DeserializeObject <List <ProfileMember> >(s.MembersCache), User = string.IsNullOrWhiteSpace(s.UserCache) ? ConvertResult(userManager.Get(s.UserUUID)) : JsonConvert.DeserializeObject <User>(s.UserCache), LocationDetail = string.IsNullOrWhiteSpace(s.LocationDetailCache) ? ConvertLocationResult(locationManager.Get(s.LocationUUID)) : JsonConvert.DeserializeObject <Location>(s.LocationDetailCache), // this.selectedProfile.LocationUUID = data.UUID; //this.selectedProfile.LocationType = data.LocationType; //single,married,ply, + genders by age? so ply-mfmfm // Profile.cs todo add to profileLogs/Members //Location { get; set; } //LocationType { get; set; } //Theme { get; set; } //View { get; set; } //UserUUID { get; set; } // // Node.cs //Status = string.Empty; //AccountUUID = string.Empty; //Deleted = false; //Private = true; //SortOrder = 0; //CreatedBy = string.Empty; //DateCreated = DateTime.MinValue; //RoleWeight = RoleFlags.MemberRoleWeights.Member; //RoleOperation = ">="; //Image = ""; }).Cast <dynamic>().ToList(); return(ServiceResponse.OK("", profiles, filter.TotalRecordCount)); }