public IActionResult CreateGroup(Domain.Socioboard.Models.Groups group)
        {
            DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv);

            //if (dbr.Find<Domain.Socioboard.Models.Groups>(t => t.adminId == group.adminId && t.groupName.Equals(group.groupName)).Count > 0)
            if (dbr.Find <Domain.Socioboard.Models.Groups>(t => t.groupName.Equals(group.groupName)).Count > 0)
            {
                return(Ok("Team Name Already Exist"));
            }
            group.createdDate = System.DateTime.UtcNow;
            int res = dbr.Add <Domain.Socioboard.Models.Groups>(group);

            if (res == 1)
            {
                Domain.Socioboard.Models.User user = dbr.FindSingle <User>(t => t.Id == group.adminId);
                long GroupId = dbr.FindSingle <Domain.Socioboard.Models.Groups>(t => t.adminId == group.adminId && t.groupName.Equals(group.groupName)).id;
                GroupMembersRepository.createGroupMember(GroupId, user, _redisCache, dbr);
                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserGroups + group.adminId);
                return(Ok("Team Added Successfully "));
            }
            else
            {
                return(Ok("Error while adding Group"));
            }
        }
Beispiel #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");
            }
        }
Beispiel #4
0
        public static string DeleteProfile(long userId, long groupId, Helper.Cache _redisCache, Model.DatabaseRepository dbr, Helper.AppSettings _appSettings)
        {
            Domain.Socioboard.Models.Groups grp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault();
            IList <Domain.Socioboard.Models.Groupprofiles> grpProfiles = dbr.Find <Groupprofiles>(t => t.groupId == groupId);

            if (grpProfiles.Count != 0)
            {
                foreach (Domain.Socioboard.Models.Groupprofiles grpProfile in grpProfiles)
                {
                    string res = string.Empty;
                    if (grpProfile != null)
                    {
                        try
                        {
                            switch (grpProfile.profileType)
                            {
                            case Domain.Socioboard.Enum.SocialProfileType.Facebook:
                            {
                                res = FacebookRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings);
                                break;
                            }

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

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

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

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

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

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

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

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

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

                            case Domain.Socioboard.Enum.SocialProfileType.Pinterest:
                            {
                                res = PinterestRepository.DeleteProfile(dbr, grpProfile.profileId, userId, _redisCache, _appSettings);
                                break;
                            }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            if (res.Equals("Deleted"))
                            {
                                dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile);
                                // dbr.Delete<Domain.Socioboard.Models.Groups>(t => t.id == groupId);
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                            }
                            else
                            {
                                if (grpProfile != null)
                                {
                                    dbr.Delete <Domain.Socioboard.Models.Groupprofiles>(grpProfile);
                                    //dbr.Delete<Domain.Socioboard.Models.Groups>(t => t.id == groupId);
                                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);
                                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        return("Issue while deleting Profile");
                    }
                }
                dbr.Delete <Domain.Socioboard.Models.Groups>(grp);
                return("Deleted");
            }
            else
            {
                dbr.Delete <Domain.Socioboard.Models.Groups>(grp);
            }


            return("Deleted");
        }
Beispiel #5
0
        public IActionResult InviteGroupMembers(long groupId, string members)
        {
            List <Groupmembers> lstGrpMembers = new List <Groupmembers>();

            if (string.IsNullOrEmpty(members))
            {
                return(BadRequest("members should not be null."));
            }
            else
            {
                string[] lstmem = members.Split(';');
                foreach (var item in lstmem)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        Groupmembers grpMember = new Groupmembers();
                        string[]     memData   = item.Split(':');
                        grpMember.email     = memData[2];
                        grpMember.firstName = memData[0];
                        grpMember.lastName  = memData[1];
                        lstGrpMembers.Add(grpMember);
                    }
                }
            }


            DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv);

            Domain.Socioboard.Models.Groups grp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.id == groupId).FirstOrDefault();
            if (grp == null)
            {
                return(BadRequest("wrong group Id"));
            }
            else if (grp.groupName.Equals(Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName))
            {
                return(BadRequest("you can't invite members to default group."));
            }
            foreach (var member in lstGrpMembers)
            {
                User inMemUser = _redisCache.Get <User>(member.email.Trim());
                if (inMemUser == null)
                {
                    inMemUser = dbr.Find <User>(t => t.EmailId.Equals(member.email.Trim())).FirstOrDefault();
                }
                member.groupid      = groupId;
                member.memberCode   = Domain.Socioboard.Helpers.SBHelper.RandomString(15);
                member.isAdmin      = false;
                member.memberStatus = Domain.Socioboard.Enum.GroupMemberStatus.MailSent;
                if (inMemUser != null)
                {
                    member.userId     = inMemUser.Id;
                    member.profileImg = inMemUser.ProfilePicUrl;
                    //todo : code to add in user notification list.
                }
                Groupmembers temp = dbr.Find <Groupmembers>(t => t.groupid == groupId && t.email == member.email).FirstOrDefault();
                if (temp == null)
                {
                    dbr.Add <Groupmembers>(member);
                    _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupMembers + groupId);
                    string path = _appEnv.WebRootPath + "\\views\\mailtemplates\\groupinvitation.html";
                    string html = System.IO.File.ReadAllText(path);
                    html = html.Replace("[FirstName]", member.firstName);
                    html = html.Replace("[JoinLink]", _appSettings.Domain + "/Home/GroupInvite?Token=" + member.memberCode + "&email=" + member.email);
                    _emailSender.SendMailSendGrid(_appSettings.frommail, "", member.email, "", "", "Socioboard Team Invitation Link", html, _appSettings.SendgridUserName, _appSettings.SendGridPassword);
                }
            }

            return(Ok());
        }