Пример #1
0
        public static string AddPageShareathon(long userId, string FacebookUrl, string FacebookPageId, string Facebookaccountid, int Timeintervalminutes, Helper.Cache _redisCache, Helper.AppSettings _appSettings, Model.DatabaseRepository dbr)
        {
            Domain.Socioboard.Models.Facebookaccounts objfacebook = Repositories.FacebookRepository.getFacebookAccount(Facebookaccountid, _redisCache, dbr);
            string pageid = Helper.FacebookHelper.GetFbPageDetails(FacebookUrl, objfacebook.AccessToken);

            string[] profileids = null;
            profileids = FacebookPageId.Split(',');
            string facebookpagename = "";

            Domain.Socioboard.Models.Mongo.PageShareathon _Shareathon = new Domain.Socioboard.Models.Mongo.PageShareathon();
            _Shareathon.Id                = ObjectId.GenerateNewId();
            _Shareathon.strId             = ObjectId.GenerateNewId().ToString();
            _Shareathon.Facebookaccountid = objfacebook.FbUserId;
            _Shareathon.Facebookusername  = objfacebook.FbUserName;
            _Shareathon.Facebookpageid    = FacebookPageId;
            _Shareathon.FacebookPageUrl   = FacebookUrl;
            _Shareathon.FacebookPageUrlId = pageid.TrimEnd(',');
            foreach (var item in profileids)
            {
                Domain.Socioboard.Models.Facebookaccounts objfacebookpage = FacebookRepository.getFacebookAccount(item, _redisCache, dbr);
                if (objfacebookpage != null)
                {
                    facebookpagename = objfacebookpage.FbUserName + ',' + facebookpagename;
                }
            }
            _Shareathon.Facebookpagename    = facebookpagename.TrimEnd(',');
            _Shareathon.FacebookStatus      = 1;
            _Shareathon.Timeintervalminutes = Timeintervalminutes;
            _Shareathon.Userid             = userId;
            _Shareathon.Lastsharetimestamp = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
            var shareathonRepository = new MongoRepository("Shareathon", _appSettings);
            var ret = shareathonRepository.Find <Domain.Socioboard.Models.Mongo.PageShareathon>(t => t.Facebookpageid == FacebookPageId && t.Facebookaccountid == Facebookaccountid && t.FacebookPageUrl == FacebookUrl && t.Userid == userId);

            var task = Task.Run(async() =>
            {
                return(await ret);
            });

            int count = task.Result.Count;

            if (count > 0)
            {
                return("Oops! Same page shareathon settings has been added already.");
            }

            shareathonRepository.Add(_Shareathon);
            return("Page shareathon has been scheduled Successfully.");
        }
Пример #2
0
        public static void RegisterAuth()
        {
            // To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter,
            // you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166

            //OAuthWebSecurity.RegisterMicrosoftClient(
            //    clientId: "",
            //    clientSecret: "");

            //OAuthWebSecurity.RegisterTwitterClient(
            //    consumerKey: "",
            //    consumerSecret: "");

            //link to SweatyShirt facebook application.
            //https://developers.facebook.com/apps/1427057544185579

            //to post to Facebook wall need add that to scope on registration, no way to do that using MS object.
            //Dictionary<string, object> extraData = new Dictionary<string, object>();
            //extraData.Add("Icon", "~/Images/facebook.png");

            /*OAuthWebSecurity.RegisterFacebookClient(
             *  appId: "416517368461806",
             *  appSecret: "b15efe8b9c46dfbced7e6f38733d71e8",
             *  displayName: "Facebook",
             *  extraData: extraData);*/

            //http://stackoverflow.com/questions/12610402/oauthwebsecurity-with-facebook-not-using-email-permission-as-expected
            //http://social.msdn.microsoft.com/Forums/wpapps/en-US/7e84e9ac-516a-4b48-b8b7-b8215e0e02a6/facebookclient-posting-a-message-oauthexception-200-200-the-user-hasnt-authorized-the
            //http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/
            //this is approach I used:
            //http://stackoverflow.com/questions/14987868/net-mvc-app-facebook-oauth-with-defiend-scope

            OAuthWebSecurity.RegisterClient(FacebookRepository.GetFacebookExtendedClient());

            //OAuthWebSecurity.RegisterGoogleClient();
        }
Пример #3
0
        public IActionResult GetPluginProfile(long groupId)
        {
            List <Domain.Socioboard.Helpers.PluginProfile> lstPluginProfile = new List <Domain.Socioboard.Helpers.PluginProfile>();
            DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv);
            List <Domain.Socioboard.Models.Groupprofiles> lstGroupprofiles = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId.Equals(groupId) && (t.profileType == Domain.Socioboard.Enum.SocialProfileType.Facebook || t.profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage || t.profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter)).ToList();

            lstGroupprofiles = lstGroupprofiles.GroupBy(t => t.profileId).Select(g => g.First()).ToList();
            foreach (var item in lstGroupprofiles)
            {
                try
                {
                    if (item.profileType == Domain.Socioboard.Enum.SocialProfileType.Facebook || item.profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage)
                    {
                        Domain.Socioboard.Models.Facebookaccounts _Facebookaccounts = FacebookRepository.getFacebookAccount(item.profileId, _redisCache, dbr);
                        if (_Facebookaccounts != null)
                        {
                            if (!string.IsNullOrEmpty(_Facebookaccounts.AccessToken))
                            {
                                if (_Facebookaccounts.IsActive)
                                {
                                    Domain.Socioboard.Helpers.PluginProfile _sb = new Domain.Socioboard.Helpers.PluginProfile();
                                    _sb.type            = "facebook";
                                    _sb.facebookprofile = _Facebookaccounts;
                                    _sb.twitterprofile  = new Domain.Socioboard.Models.TwitterAccount();
                                    lstPluginProfile.Add(_sb);
                                }
                            }
                        }
                    }
                    if (item.profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter)
                    {
                        Domain.Socioboard.Models.TwitterAccount _TwitterAccount = TwitterRepository.getTwitterAccount(item.profileId, _redisCache, dbr);
                        if (_TwitterAccount != null)
                        {
                            if (_TwitterAccount.isActive)
                            {
                                Domain.Socioboard.Helpers.PluginProfile _sb = new Domain.Socioboard.Helpers.PluginProfile();
                                _sb.type            = "twitter";
                                _sb.twitterprofile  = _TwitterAccount;
                                _sb.facebookprofile = new Domain.Socioboard.Models.Facebookaccounts();
                                lstPluginProfile.Add(_sb);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(Ok(lstPluginProfile));
                }
            }
            return(Ok(lstPluginProfile));
        }
Пример #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");
        }
        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");
            }
        }
Пример #6
0
 public FacebookBusiness()
 {
     repository = new FacebookRepository();
 }
Пример #7
0
        private static string DeleteGroup(long userId, string profileId, Cache _redisCache, DatabaseRepository dbr, AppSettings _appSettings, Groupprofiles grpProfile, string res)
        {
            switch (grpProfile.profileType)
            {
            case SocialProfileType.Facebook:
            {
                res = FacebookRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                break;
            }

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

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

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

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

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

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

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

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

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

            case SocialProfileType.Pinterest:
            {
                res = PinterestRepository.DeleteProfile(dbr, profileId, userId, _redisCache, _appSettings);
                break;
            }
            }

            return(res);
        }
Пример #8
0
        private static void AddedProfileDetails(Cache redisCache, DatabaseRepository dbr, List <profilesdetail> groupProfiles, Groupprofiles profile)
        {
            switch (profile.profileType)
            {
            case SocialProfileType.Facebook:
            {
                var fbAcc          = FacebookRepository.getFacebookAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    Fbaccount = fbAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.FacebookFanPage:
            {
                var fbPageAcc      = FacebookRepository.getFacebookAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    Fbaccount = fbPageAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.Twitter:
            {
                var twtAcc         = TwitterRepository.getTwitterAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    Twtaccount = twtAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.Instagram:
            {
                var insAcc         = InstagramRepository.getInstagramAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    Instaaccount = insAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.GPlus:
            {
                var gPlusAcc       = GplusRepository.getGPlusAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    Gplusaccount = gPlusAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.LinkedIn:
            {
                var linkedInAcc    = LinkedInAccountRepository.getLinkedInAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    LinkdInaccount = linkedInAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.LinkedInComapanyPage:
            {
                var linkedCompanyAcc = LinkedInAccountRepository.getLinkedinCompanyPage(profile.profileId, redisCache, dbr);
                var profileDetails   = new profilesdetail {
                    LinkdINcompanyaccount = linkedCompanyAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.YouTube:
            {
                var youtubeChannel = GplusRepository.getYTChannel(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    Ytubeaccount = youtubeChannel
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.GoogleAnalytics:
            {
                var gAAcc          = GplusRepository.getGAAccount(profile.profileId, redisCache, dbr);
                var profileDetails = new profilesdetail {
                    GAaccount = gAAcc
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.Pinterest:
            {
                var pInterestAccountDetail = PinterestRepository.getPinterestAccountDetail(profile.profileId, redisCache, dbr);
                var profileDetails         = new profilesdetail {
                    Pintrestaccount = pInterestAccountDetail
                };
                groupProfiles.Add(profileDetails);
                break;
            }

            case SocialProfileType.GplusPage:
                break;

            case SocialProfileType.Tumblr:
                break;

            case SocialProfileType.FacebookPublicPage:
                break;

            case SocialProfileType.DropBox:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #9
0
        public ActionResult Index(SweatyTShirt sweatyTShirt)
        {
            int userID = UserID;

            sweatyTShirt.UserID = userID;

            using (CompetitionRepository competitionRepository = new CompetitionRepository())
            {
                if (sweatyTShirt.IsSave)
                {
                    sweatyTShirt.CreatedDate = DateTime.Now;
                    competitionRepository.AddSweatyTShirt(sweatyTShirt);
                    ViewBag.Purr = new Purr()
                    {
                        Title = "Success", Message = "Sweaty-T-Shirt was successfully added."
                    };
                }

                sweatyTShirt.Competitions = competitionRepository
                                            .GetUserInCompetitionsForUser(userID)
                                            .Where(o => o.IsActive)
                                            .Select(o => o.Competition).ToList();

                if (sweatyTShirt.Competitions.Count > 0)
                {
                    if (sweatyTShirt.CompetitionID > 0)
                    {
                        sweatyTShirt.Competition = sweatyTShirt.Competitions.FirstOrDefault(o => o.CompetitionID == sweatyTShirt.CompetitionID);
                    }
                    else
                    {
                        sweatyTShirt.Competition   = sweatyTShirt.Competitions[0];
                        sweatyTShirt.CompetitionID = sweatyTShirt.Competition.CompetitionID;
                    }

                    if (sweatyTShirt.Competition == null)
                    {
                        throw new ApplicationException(string.Format("Unable to retrieve Competition object for sweatyTShirt.CompetitionID {0}", sweatyTShirt.CompetitionID));
                    }

                    sweatyTShirt.Competition.CompetitionProgressBars =
                        ControllerHelpers.GetCompetitionProgressBars(competitionRepository,
                                                                     sweatyTShirt.CompetitionID);

                    if (sweatyTShirt.IsSave)
                    {
                        /* emails are sent in separate thread, see global.asax.cs*/
                        if (sweatyTShirt.PostToFacebook)
                        {
                            FacebookRepository.PostToFacebook(sweatyTShirt);
                        }
                    }
                }
            }

            if (TempData[ControllerHelpers.PURR] != null)
            {
                ViewBag.Purr = TempData[ControllerHelpers.PURR];
                TempData[ControllerHelpers.PURR] = null;
            }

            sweatyTShirt.IsSave      = false;
            sweatyTShirt.Description = null;
            //will get client side validation errors because manually adding model to view, need to clear them.
            ModelState.Clear();
            return(View(sweatyTShirt));
        }
Пример #10
0
        public IActionResult SchedulePagePost(string profileId, int TimeInterVal, long UserId)
        {
            int addedPageCount     = 0;
            int invalidaccessToken = 0;

            profileId = profileId.TrimEnd(',');
            try
            {
                try
                {
                    foreach (var items in profileId.Split(','))
                    {
                        string pageUrls = Request.Form["pageUrls"];
                        Domain.Socioboard.Models.Facebookaccounts _Facebookaccounts = new Facebookaccounts();
                        DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv);
                        _Facebookaccounts = FacebookRepository.getFacebookAccount(items, _redisCache, dbr);
                        List <Domain.Socioboard.Models.Mongo.PageDetails> pageid = Helper.FacebookHelper.GetFbPagePostDetails(pageUrls, _Facebookaccounts.AccessToken);
                        if (pageid.Count == 0)
                        {
                            invalidaccessToken++;
                        }
                        foreach (Domain.Socioboard.Models.Mongo.PageDetails item in pageid)
                        {
                            addedPageCount++;
                            if (_Facebookaccounts != null)
                            {
                                LinkShareathon _LinkShareathon = new LinkShareathon();
                                _LinkShareathon.Id               = ObjectId.GenerateNewId();
                                _LinkShareathon.strId            = ObjectId.GenerateNewId().ToString();
                                _LinkShareathon.Userid           = UserId;
                                _LinkShareathon.Facebookusername = _Facebookaccounts.FbUserName;
                                _LinkShareathon.FacebookPageUrl  = item.PageUrl;
                                _LinkShareathon.TimeInterVal     = TimeInterVal;
                                _LinkShareathon.Facebookpageid   = item.PageId;
                                _LinkShareathon.IsActive         = true;
                                MongoRepository _ShareathonRepository = new MongoRepository("LinkShareathon", _appSettings);
                                _ShareathonRepository.Add(_LinkShareathon);
                                new Thread(delegate()
                                {
                                    Helper.FacebookHelper.schedulePage_Post(_Facebookaccounts.AccessToken, item.PageId, TimeInterVal);
                                }).Start();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            catch (System.Exception ex)
            {
            }
            if (addedPageCount == profileId.Length)
            {
                return(Ok("successfully added"));
            }
            else if (invalidaccessToken > 0)
            {
                return(Ok(invalidaccessToken + "pages access token expired"));
            }

            return(Ok("successfully added"));
        }