public ServiceResult SetActiveProfile(string profileUUID) { ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); GreenWerx.Models.Membership.Profile profile = profileManager.SetActiveProfile(profileUUID, CurrentUser.UUID, CurrentUser.AccountUUID); return(ServiceResponse.OK("", profile)); }
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.ValueType.EqualsIgnoreCase("ImagePath") == false) { return(ServiceResponse.Error("Attribute is not an image path type.")); } ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); var tmp = profileManager.GetProfile(CurrentUser.UUID, CurrentUser.AccountUUID, true); if (tmp.Code != 200) { return(tmp); } GreenWerx.Models.Membership.Profile profile = (Profile)tmp.Result; profile.Image = attribute.Image; return(ServiceResponse.OK("", profile.Image)); }
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 DeleteAttribute(string UUID)//todo bookmark latest test this. { if (string.IsNullOrWhiteSpace(UUID)) { return(ServiceResponse.Error("No id was sent.")); } if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } AttributeManager atm = new AttributeManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); var res = atm.Get(UUID); if (res.Code != 200) { return(res); } var attribute = res.Result as TMG.Attribute; if (attribute.ValueType.EqualsIgnoreCase("ImagePath") == false) { return(atm.Delete(attribute, true)); } string root = System.Web.HttpContext.Current.Server.MapPath("~/Content/Uploads/" + this.CurrentUser.UUID); string fileName = attribute.Image.GetFileNameFromUrl(); //todo get folder and file from attribute.Image => https://localhost:44318/Content/Uploads/8ac0adc1e7154afda15069c822d68d6d/20190226_082504appicon.png string pathToFile = Path.Combine(root, fileName); DocumentManager dm = new DocumentManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); if (dm.DeleteFile(attribute, pathToFile).Code != 200) { return(ServiceResponse.Error("Failed to delete file " + fileName)); } DataFilter filter = this.GetFilter(Request); List <TMG.Attribute> attributes = atm.GetAttributes(this.CurrentUser.AccountUUID, ref filter) .Where(w => w.UUIDType.EqualsIgnoreCase("ImagePath") && w.Value == attribute.UUID && w.Image.Contains(fileName)).ToList(); // Update attributes that are using this image. foreach (TMG.Attribute att in attributes) { // if (am.DeleteSetting(setting.UUID).Code != 200) // return ServiceResponse.Error("Failed to delete image setting for file " + fileName); att.Image = "/assets/img/blankprofile.png"; // todo change image. Monetize? } var res1 = atm.Delete(attribute, true); ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, Request.Headers.Authorization?.Parameter); var tmp = profileManager.GetProfile(CurrentUser.UUID, CurrentUser.AccountUUID, true); if (tmp.Code != 200) { return(tmp); } GreenWerx.Models.Membership.Profile profile = (Profile)tmp.Result; if (profile.Image.Contains(fileName)) { profile.Image = "/assets/img/blankprofile.png"; } return(profileManager.UpdateProfile(profile)); }
//todo add to role if not already in it public ServiceResult Insert(VerificationEntry s) { var CurrentUser = this.GetUser(SessionKey); if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } s.VerifierAccountUUID = CurrentUser.AccountUUID; s.VerifierUUID = CurrentUser.UUID; s.VerificationDate = DateTime.UtcNow; s.VerifierProfileUUID = this.GetProfileUUID(this.SessionKey); GreenWerx.Models.Membership.Profile verifierProfile = null; //todo check if set, if not use profile -> locationUUID if (string.IsNullOrWhiteSpace(s.VerifierLocationUUID)) { ProfileManager profileManager = new ProfileManager(this._connectionKey, this.SessionKey); var res = profileManager.Get(s.VerifierProfileUUID); try { if (res.Code == 200) { verifierProfile = (GreenWerx.Models.Membership.Profile)res.Result; s.VerifierLocationUUID = verifierProfile.LocationUUID; } } catch {//not that important. } } var vcts = GetVerificationEntries(s.RecipientProfileUUID); //one user can do multiple adds. so make it that they can only verify every 90 days. var tmp = GetVerificationEntries(s.RecipientProfileUUID) .FirstOrDefault(w => w.VerifierUUID == CurrentUser.UUID && w.VerificationType.EqualsIgnoreCase(s.VerificationType) && w.VerificationDate.AddDays(-90) < DateTime.UtcNow );// if (tmp != null) { return(ServiceResponse.Error("You may only verify every ninety days.")); } RoleManager rm = new RoleManager(this._connectionKey, CurrentUser); var userRole = rm.GetRolesForUser(CurrentUser.UUID, CurrentUser.AccountUUID) .Where(w => w.Category.EqualsIgnoreCase("member")) .OrderByDescending(o => o.RoleWeight).FirstOrDefault(); if (userRole == null) { return(ServiceResponse.Error("You must be assigned a role to verify.")); } s.VerifierRoleUUID = userRole.UUID; //verificationType s.Weight = userRole.Weight; //<== role.Category of verifying user var relationshipRole = rm.GetRoles(CurrentUser.AccountUUID) .FirstOrDefault(w => w.CategoryRoleName.EqualsIgnoreCase(verifierProfile.RelationshipStatus) && w.Category.EqualsIgnoreCase("member")); s.Multiplier = relationshipRole.Weight;// <== of verifying user verifierProfile.RelationshipStatus var verTypeRole = rm.GetRoles(CurrentUser.AccountUUID).FirstOrDefault(w => w.Category.EqualsIgnoreCase("verified") && w.CategoryRoleName.EqualsIgnoreCase(s.VerificationType)); //Category CategoryRoleName //verified critical user //verified ambassador //verified geolocation //verified photo submission //verified other member s.VerificationTypeMultiplier = verTypeRole.Weight; s.Points = ((s.VerificationTypeMultiplier) + s.Weight) * s.Multiplier; string destinationRoleUUID = verTypeRole.UUID;// "verification role"; //TODO get the uuid for the verification role using (var context = new GreenWerxDbContext(this._connectionKey)) { //todo add RecipientMemberRoleUUID //this is the member role (UsersInRoles) the user ended kup in due to the verification. // create default roles fore verification //todo make this a transacion and add to verification role var ur = context.GetAll <UserRole>().Any(rpw => rpw.ReferenceUUID == s.RecipientUUID && rpw.AccountUUID == s.RecipientAccountUUID && rpw.RoleUUID == destinationRoleUUID); if (ur == false) // if not in role already { // add to role.. //var role = context.GetAll<Role>() // .FirstOrDefault(w => w.AccountUUID == s.RecipientAccountUUID && // w.Category.EqualsIgnoreCase("verified") && // w.CategoryRoleName.EqualsIgnoreCase(s.VerificationType) // ); var guid = Guid.NewGuid().ToString("N"); var userVerifiedRole = new UserRole() { GUUID = guid, UUID = guid, AccountUUID = s.RecipientAccountUUID, Action = "get", Active = true, AppType = "web", CreatedBy = s.VerifierUUID, DateCreated = DateTime.UtcNow, Deleted = false, EndDate = DateTime.UtcNow.AddDays(90), Name = verTypeRole.Name, ReferenceUUID = s.RecipientUUID, ReferenceType = "User", UUIDType = "UserRole", RoleOperation = verTypeRole.RoleOperation, RoleWeight = verTypeRole.RoleWeight, RoleUUID = verTypeRole.UUID, Image = verTypeRole.Image, StartDate = DateTime.UtcNow, }; context.Insert <UserRole>(userVerifiedRole); guid = Guid.NewGuid().ToString("N"); var profileRole = new UserRole() { GUUID = guid, UUID = guid, AccountUUID = s.RecipientAccountUUID, Action = "get", Active = true, AppType = "web", CreatedBy = s.VerifierUUID, DateCreated = DateTime.UtcNow, Deleted = false, EndDate = DateTime.UtcNow.AddDays(90), Name = verTypeRole.Name, ReferenceUUID = s.RecipientProfileUUID, ReferenceType = "Profile", UUIDType = "UserRole", RoleOperation = verTypeRole.RoleOperation, RoleWeight = verTypeRole.RoleWeight, RoleUUID = verTypeRole.UUID, Image = verTypeRole.Image, StartDate = DateTime.UtcNow, }; context.Insert <UserRole>(profileRole); } if (context.Insert <VerificationEntry>(s)) { return(ServiceResponse.OK("", s)); } } return(ServiceResponse.Error("An error occurred inserting verification.")); }