public static int AddGroupProfile(Int64 GroupId, string ProfileId, string ProfileName, Int64 ProfileOwnerId, string ProfilePic, Domain.Socioboard.Enum.SocialProfileType profileType, Model.DatabaseRepository dbr)
 {
     Domain.Socioboard.Models.Groupprofiles grpProfile = new Domain.Socioboard.Models.Groupprofiles();
     grpProfile.groupId        = GroupId;
     grpProfile.profileId      = ProfileId;
     grpProfile.profileName    = ProfileName;
     grpProfile.profileOwnerId = ProfileOwnerId;
     grpProfile.profilePic     = ProfilePic;
     grpProfile.profileType    = profileType;
     return(dbr.Add <Domain.Socioboard.Models.Groupprofiles>(grpProfile));
 }
Esempio n. 2
0
        public IActionResult AddProfileToGroup(string profileId, long groupId, long userId, Domain.Socioboard.Enum.SocialProfileType profileType)
        {
            DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv);
            List <Domain.Socioboard.Models.Groupprofiles> lstGroupProfiles = GroupProfilesRepository.getGroupProfiles(groupId, _redisCache, dbr);

            if (lstGroupProfiles.Where(t => t.profileId.Equals(profileId)).Count() > 0)
            {
                return(BadRequest("profile already added"));
            }
            else
            {
                Domain.Socioboard.Models.Groups grp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault();
                if (grp == null)
                {
                    return(BadRequest("Invalid groupId"));
                }
                else
                {
                    Domain.Socioboard.Models.Groupprofiles grpProfile = new Domain.Socioboard.Models.Groupprofiles();
                    if (profileType == Domain.Socioboard.Enum.SocialProfileType.Facebook || profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage || profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage)
                    {
                        Domain.Socioboard.Models.Facebookaccounts fbAcc = Repositories.FacebookRepository.getFacebookAccount(profileId, _redisCache, dbr);
                        if (fbAcc == null)
                        {
                            return(BadRequest("Invalid profileId"));
                        }
                        if (fbAcc.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = fbAcc.FbUserName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = "http://graph.facebook.com/" + fbAcc.FbUserId + "/picture?type=small";
                        grpProfile.profileType    = profileType;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter)
                    {
                        Domain.Socioboard.Models.TwitterAccount twtAcc = Repositories.TwitterRepository.getTwitterAccount(profileId, _redisCache, dbr);
                        if (twtAcc == null)
                        {
                            return(BadRequest("Invalid profileId"));
                        }
                        if (twtAcc.userId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = twtAcc.twitterScreenName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = twtAcc.profileImageUrl;
                        grpProfile.profileType    = Domain.Socioboard.Enum.SocialProfileType.Twitter;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.GPlus)
                    {
                        Domain.Socioboard.Models.Googleplusaccounts gplusAccount = Repositories.GplusRepository.getGPlusAccount(profileId, _redisCache, dbr);
                        if (gplusAccount == null)
                        {
                            return(BadRequest("Invalid ProfileId"));
                        }
                        if (gplusAccount.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = gplusAccount.GpUserName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = gplusAccount.GpProfileImage;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics)
                    {
                        Domain.Socioboard.Models.GoogleAnalyticsAccount gplusAccount = Repositories.GplusRepository.getGAAccount(profileId, _redisCache, dbr);
                        if (gplusAccount == null)
                        {
                            return(BadRequest("Invalid ProfileId"));
                        }
                        if (gplusAccount.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = gplusAccount.GaProfileName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = gplusAccount.ProfilePicUrl;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.Instagram)
                    {
                        Domain.Socioboard.Models.Instagramaccounts _Instagramaccounts = Repositories.InstagramRepository.getInstagramAccount(profileId, _redisCache, dbr);
                        if (_Instagramaccounts == null)
                        {
                            return(BadRequest("Invalid ProfileId"));
                        }
                        if (_Instagramaccounts.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = _Instagramaccounts.InsUserName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = _Instagramaccounts.ProfileUrl;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.LinkedIn)
                    {
                        Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = Repositories.LinkedInAccountRepository.getLinkedInAccount(profileId, _redisCache, dbr);
                        if (_LinkedInAccount == null)
                        {
                            return(BadRequest("Invalid ProfileId"));
                        }
                        if (_LinkedInAccount.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = _LinkedInAccount.LinkedinUserName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = _LinkedInAccount.ProfileImageUrl;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage)
                    {
                        Domain.Socioboard.Models.LinkedinCompanyPage _LinkedInAccount = Repositories.LinkedInAccountRepository.getLinkedinCompanyPage(profileId, _redisCache, dbr);
                        if (_LinkedInAccount == null)
                        {
                            return(BadRequest("Invalid ProfileId"));
                        }
                        if (_LinkedInAccount.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = _LinkedInAccount.LinkedinPageName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = _LinkedInAccount.LogoUrl;
                    }
                    else if (profileType == Domain.Socioboard.Enum.SocialProfileType.YouTube)
                    {
                        Domain.Socioboard.Models.YoutubeChannel _YoutubeChannel = Repositories.GplusRepository.getYTChannel(profileId, _redisCache, dbr);
                        if (_YoutubeChannel == null)
                        {
                            return(BadRequest("Invalid ProfileId"));
                        }
                        if (_YoutubeChannel.UserId != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = _YoutubeChannel.YtubeChannelName;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = _YoutubeChannel.ChannelpicUrl;
                    }
                    if (profileType == Domain.Socioboard.Enum.SocialProfileType.Pinterest)
                    {
                        Domain.Socioboard.Models.PinterestAccount pinAcc = dbr.Find <Domain.Socioboard.Models.PinterestAccount>(t => t.username.Equals(profileId)).FirstOrDefault();
                        if (pinAcc == null)
                        {
                            return(BadRequest("Invalid profileId"));
                        }
                        if (pinAcc.userid != userId)
                        {
                            return(BadRequest("profile is added by other user"));
                        }
                        grpProfile.profileName    = pinAcc.firstname + " " + pinAcc.lastname;
                        grpProfile.profileOwnerId = userId;
                        grpProfile.profilePic     = pinAcc.profileimgaeurl;
                        grpProfile.profileType    = profileType;
                    }
                    grpProfile.entryDate   = DateTime.UtcNow;
                    grpProfile.groupId     = grp.id;
                    grpProfile.profileId   = profileId;
                    grpProfile.profileType = profileType;
                    dbr.Add <Domain.Socioboard.Models.Groupprofiles>(grpProfile);
                    //codes to clear cache
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                    //end codes to clear cache
                    return(Ok("Added Successfully"));
                }
            }
        }
        public static string DeleteProfile(long groupId, long userId, string profileId, Helper.Cache _redisCache, Model.DatabaseRepository dbr, Helper.AppSettings _appSettings)
        {
            Domain.Socioboard.Models.Groupprofiles grpProfile = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupId && t.profileId.Equals(profileId)).FirstOrDefault();
            Domain.Socioboard.Models.Groups        grp        = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault();
            string res = string.Empty;

            if (grpProfile != null)
            {
                if (grp.groupName.Equals(Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName))
                {
                    switch (grpProfile.profileType)
                    {
                    case Domain.Socioboard.Enum.SocialProfileType.Facebook:
                    {
                        res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage:
                    {
                        res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage:
                    {
                        res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.Twitter:
                    {
                        res = TwitterRepository.DeleteProfile(dbr, profileId, userId, _redisCache);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.LinkedIn:
                    {
                        res = LinkedInAccountRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage:
                    {
                        res = LinkedInAccountRepository.DeleteCompanyPageProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.Instagram:
                    {
                        res = InstagramRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics:
                    {
                        res = GplusRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }

                    case Domain.Socioboard.Enum.SocialProfileType.GPlus:
                    {
                        res = GplusRepository.DeleteGplusProfile(dbr, profileId, userId, _redisCache, _appSettings);
                        break;
                    }
                    }
                }
                else
                {
                    Groups defaultGroup = GroupsRepository.getAllGroupsofUser(userId, _redisCache, dbr).Find(t => t.groupName.Equals(Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName));
                    List <Groupprofiles> defalutGroupProfiles = getGroupProfiles(defaultGroup.id, _redisCache, dbr);
                    if (defalutGroupProfiles != null && defalutGroupProfiles.Count(t => t.profileId.Equals(profileId)) <= 0)
                    {
                        switch (grpProfile.profileType)
                        {
                        case Domain.Socioboard.Enum.SocialProfileType.Facebook:
                        {
                            res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage:
                        {
                            res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.FacebookPublicPage:
                        {
                            res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.Twitter:
                        {
                            res = TwitterRepository.DeleteProfile(dbr, profileId, userId, _redisCache);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.LinkedIn:
                        {
                            res = LinkedInAccountRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.LinkedInComapanyPage:
                        {
                            res = LinkedInAccountRepository.DeleteCompanyPageProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.Instagram:
                        {
                            res = InstagramRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.GoogleAnalytics:
                        {
                            res = GplusRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }

                        case Domain.Socioboard.Enum.SocialProfileType.GPlus:
                        {
                            res = GplusRepository.DeleteGplusProfile(dbr, profileId, userId, _redisCache, _appSettings);
                            break;
                        }
                        }
                    }
                    else
                    {
                        res = "Deleted";
                    }
                }

                if (res.Equals("Deleted"))
                {
                    dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile);
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                    return("Deleted");
                }
                else
                {
                    if (grpProfile != null)
                    {
                        dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile);
                        _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                        _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                        return("Deleted");
                    }
                    return(res);
                }
            }
            else
            {
                return("Issue while deleting Profile");
            }
        }