Пример #1
0
        public IActionResult GoogleLogin(string code, Domain.Socioboard.Enum.SBAccountType accType)
        {
            string ret          = string.Empty;
            string objRefresh   = string.Empty;
            string refreshToken = string.Empty;
            string access_token = string.Empty;

            oAuthTokenGPlus ObjoAuthTokenGPlus = new oAuthTokenGPlus(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri);
            oAuthToken      objToken           = new oAuthToken(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri);
            JObject         userinfo           = new JObject();

            try
            {
                objRefresh = ObjoAuthTokenGPlus.GetRefreshToken(code);
                JObject objaccesstoken = JObject.Parse(objRefresh);
                _logger.LogInformation(objaccesstoken.ToString());
                try
                {
                    refreshToken = objaccesstoken["refresh_token"].ToString();
                }
                catch { }
                access_token = objaccesstoken["access_token"].ToString();
                string user = objToken.GetUserInfo("self", access_token.ToString());
                _logger.LogInformation(user);
                userinfo = JObject.Parse(JArray.Parse(user)[0].ToString());
            }
            catch (Exception ex)
            {
                //access_token = objaccesstoken["access_token"].ToString();
                //ObjoAuthTokenGPlus.RevokeToken(access_token);
                _logger.LogInformation(ex.Message);
                _logger.LogError(ex.StackTrace);
                ret = "Access Token Not Found";
                return(Ok(ret));
            }

            string EmailId = string.Empty;

            try
            {
                EmailId = (Convert.ToString(userinfo["email"]));
            }
            catch { }
            if (string.IsNullOrEmpty(EmailId))
            {
                return(Ok("Google Not retuning Email"));
            }


            try
            {
                User inMemUser = _redisCache.Get <User>(EmailId);
                if (inMemUser != null)
                {
                    return(Ok(inMemUser));
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
                _logger.LogError(ex.StackTrace);
            }



            DatabaseRepository dbr     = new DatabaseRepository(_logger, _appEnv);
            IList <User>       lstUser = dbr.Find <User>(t => t.EmailId.Equals(EmailId));

            if (lstUser != null && lstUser.Count() > 0)
            {
                DateTime d1 = DateTime.UtcNow;
                //User userTable = dbr.Single<User>(t => t.EmailId == EmailId);
                //userTable.LastLoginTime = d1;
                lstUser.First().LastLoginTime = d1;
                dbr.Update <User>(lstUser.First());
                _redisCache.Set <User>(lstUser.First().EmailId, lstUser.First());
                return(Ok(lstUser.First()));
            }
            else
            {
                Domain.Socioboard.Models.Googleplusaccounts gplusAcc = Api.Socioboard.Repositories.GplusRepository.getGPlusAccount(Convert.ToString(userinfo["id"]), _redisCache, dbr);
                if (gplusAcc != null && gplusAcc.IsActive == true)
                {
                    return(Ok("GPlus account added by other user."));
                }


                Domain.Socioboard.Models.User user = new Domain.Socioboard.Models.User();
                if (accType == Domain.Socioboard.Enum.SBAccountType.Free)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Free;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Deluxe)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Deluxe;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Premium)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Premium;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Topaz)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Topaz;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Platinum)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Platinum;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Gold)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Gold;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Ruby)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Ruby;
                }
                else if (accType == Domain.Socioboard.Enum.SBAccountType.Standard)
                {
                    user.AccountType = Domain.Socioboard.Enum.SBAccountType.Standard;
                }
                user.PaymentType        = Domain.Socioboard.Enum.PaymentType.paypal;
                user.ActivationStatus   = Domain.Socioboard.Enum.SBUserActivationStatus.Active;
                user.CreateDate         = DateTime.UtcNow;
                user.EmailId            = EmailId;
                user.ExpiryDate         = DateTime.UtcNow.AddDays(1);
                user.UserName           = "******";
                user.EmailValidateToken = "Google";
                user.UserType           = "User";
                user.LastLoginTime      = DateTime.UtcNow;
                user.PaymentStatus      = Domain.Socioboard.Enum.SBPaymentStatus.UnPaid;
                try
                {
                    user.FirstName = (Convert.ToString(userinfo["name"]));
                }
                catch { }
                user.RegistrationType = Domain.Socioboard.Enum.SBRegistrationType.Google;

                int  SavedStatus = dbr.Add <Domain.Socioboard.Models.User>(user);
                User nuser       = dbr.Single <User>(t => t.EmailId.Equals(user.EmailId));
                if (SavedStatus == 1 && nuser != null)
                {
                    Groups group = new Groups();
                    group.adminId     = nuser.Id;
                    group.createdDate = DateTime.UtcNow;
                    group.groupName   = Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName;
                    SavedStatus       = dbr.Add <Groups>(group);
                    if (SavedStatus == 1)
                    {
                        Groups ngrp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.adminId == nuser.Id && t.groupName.Equals(Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName)).FirstOrDefault();
                        GroupMembersRepository.createGroupMember(ngrp.id, nuser, _redisCache, dbr);
                        // Adding GPlus Profile
                        Api.Socioboard.Repositories.GplusRepository.AddGplusAccount(userinfo, dbr, nuser.Id, ngrp.id, access_token, refreshToken, _redisCache, _appSettings, _logger);
                    }
                }
                return(Ok(nuser));
            }
        }
Пример #2
0
        public async Task <IActionResult> Index()
        {
            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");

            if (user == null)
            {
                return(RedirectToAction("Index", "Index"));
            }

            try
            {
                if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Free)
                {
                    ViewBag.AccountType = "Free";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Deluxe)
                {
                    ViewBag.AccountType = "Deluxe";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Premium)
                {
                    ViewBag.AccountType = "Premium";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Topaz)
                {
                    ViewBag.AccountType = "Topaz";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Platinum)
                {
                    ViewBag.AccountType = "Platinum";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Gold)
                {
                    ViewBag.AccountType = "Gold";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Ruby)
                {
                    ViewBag.AccountType = "Ruby";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Standard)
                {
                    ViewBag.AccountType = "Standard";
                }
                if (user.ExpiryDate < DateTime.UtcNow)
                {
                    //return RedirectToAction("UpgradePlans", "Index");
                    if (user.TrailStatus != Domain.Socioboard.Enum.UserTrailStatus.inactive)
                    {
                        List <KeyValuePair <string, string> > Param = new List <KeyValuePair <string, string> >();
                        Param.Add(new KeyValuePair <string, string>("Id", user.Id.ToString()));
                        HttpResponseMessage respon = await WebApiReq.PostReq("/api/User/UpdateTrialStatus", Param, "", "", _appSettings.ApiDomain);

                        if (respon.IsSuccessStatusCode)
                        {
                            Domain.Socioboard.Models.User _user = await respon.Content.ReadAsAsync <Domain.Socioboard.Models.User>();

                            HttpContext.Session.SetObjectAsJson("User", _user);
                            user = _user;
                        }
                    }
                }
                else if ((user.PayPalAccountStatus == Domain.Socioboard.Enum.PayPalAccountStatus.notadded || user.PayPalAccountStatus == Domain.Socioboard.Enum.PayPalAccountStatus.inprogress) && (user.AccountType != Domain.Socioboard.Enum.SBAccountType.Free))
                {
                    HttpContext.Session.SetObjectAsJson("paymentsession", true);
                    return(RedirectToAction("PayPalAccount", "Home", new { emailId = user.EmailId, IsLogin = true }));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Index"));
            }
            HttpResponseMessage response = await WebApiReq.GetReq("/api/Groups/GetUserGroups?userId=" + user.Id, "", "", _appSettings.ApiDomain);

            if (response.IsSuccessStatusCode)
            {
                try
                {
                    List <Domain.Socioboard.Models.Groups> groups = await response.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groups> >();

                    ViewBag.groups = Newtonsoft.Json.JsonConvert.SerializeObject(groups);
                    string sessionSelectedGroupId = HttpContext.Session.GetObjectFromJson <string>("selectedGroupId");
                    if (!string.IsNullOrEmpty(sessionSelectedGroupId))
                    {
                        ViewBag.selectedGroupId = sessionSelectedGroupId;
                        HttpResponseMessage groupProfilesResponse = await WebApiReq.GetReq("/api/GroupProfiles/GetGroupProfiles?groupId=" + sessionSelectedGroupId, "", "", _appSettings.ApiDomain);

                        if (groupProfilesResponse.IsSuccessStatusCode)
                        {
                            List <Domain.Socioboard.Models.Groupprofiles> groupProfiles = await groupProfilesResponse.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groupprofiles> >();

                            ViewBag.groupProfiles = Newtonsoft.Json.JsonConvert.SerializeObject(groupProfiles);
                            // string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);
                            // int count = Convert.ToInt32(profileCount);
                            int count    = groupProfiles.Count;
                            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);
                            ViewBag.profileCount = count;
                            ViewBag.MaxCount     = MaxCount;
                            ViewBag.AccountType  = user.AccountType;
                            if (count > MaxCount)
                            {
                                ViewBag.downgrade = "true";
                            }
                            else
                            {
                                ViewBag.downgrade = "false";
                            }
                        }
                    }
                    else
                    {
                        long selectedGroupId = groups.FirstOrDefault(t => t.groupName == Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName).id;
                        HttpContext.Session.SetObjectAsJson("selectedGroupId", selectedGroupId);
                        ViewBag.selectedGroupId = selectedGroupId;
                        HttpResponseMessage groupProfilesResponse = await WebApiReq.GetReq("/api/GroupProfiles/GetGroupProfiles?groupId=" + selectedGroupId, "", "", _appSettings.ApiDomain);

                        if (groupProfilesResponse.IsSuccessStatusCode)
                        {
                            List <Domain.Socioboard.Models.Groupprofiles> groupProfiles = await groupProfilesResponse.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groupprofiles> >();

                            ViewBag.groupProfiles = Newtonsoft.Json.JsonConvert.SerializeObject(groupProfiles);
                            //string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);
                            // int count = Convert.ToInt32(profileCount);
                            int count    = groupProfiles.Count;
                            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);
                            ViewBag.profileCount = count;
                            ViewBag.MaxCount     = MaxCount;
                            if (count > MaxCount)
                            {
                                ViewBag.downgrade = "true";
                            }
                            else
                            {
                                ViewBag.downgrade = "false";
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    HttpContext.Session.Remove("User");
                    HttpContext.Session.Remove("selectedGroupId");
                    HttpContext.Session.Clear();
                    ViewBag.user            = null;
                    ViewBag.selectedGroupId = null;
                    ViewBag.groupProfiles   = null;
                    TempData["Error"]       = "Some thing went wrong.";
                    return(RedirectToAction("Index", "Index"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Index"));
            }
            ViewBag.user = Newtonsoft.Json.JsonConvert.SerializeObject(user);
            return(View());
        }
Пример #3
0
        // GET: /<controller>/
        public async Task <IActionResult> ManageUser(string param)
        {
            Domain.Socioboard.Models.User _user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");
            if (_user == null)
            {
                return(RedirectToAction("Index", "Index"));
            }
            else
            {
                Domain.Socioboard.Models.UserDetails user = new Domain.Socioboard.Models.UserDetails();
                if (param == null)
                {
                    if (j == 0)
                    {
                        try
                        {
                            HttpResponseMessage response = await WebApiReq.GetReq("/api/User/GetUserAdmin?value=" + 0, "", "", _appSettings.ApiDomain);

                            if (response.IsSuccessStatusCode)
                            {
                                user = await response.Content.ReadAsAsync <Domain.Socioboard.Models.UserDetails>();
                            }
                            //count = 100;
                            //j = j + 500;
                            // ViewBag.Count = user.Count();
                            ViewBag.TotalCount = user.count;
                            ViewBag.Count      = user._user.Count();
                            ViewBag.details    = user._user;
                            ViewBag.ApiDomain  = _appSettings.ApiDomain;
                            ViewBag.Domain     = _appSettings.Domain;
                            return(View("ManageUser"));
                        }
                        catch (Exception ex)
                        {
                            return(View("ManageUser"));
                        }
                    }
                    else
                    {
                        HttpResponseMessage response = await WebApiReq.GetReq("/api/User/GetUserAdmin?value=" + j, "", "", _appSettings.ApiDomain);

                        if (response.IsSuccessStatusCode)
                        {
                            user = await response.Content.ReadAsAsync <Domain.Socioboard.Models.UserDetails>();
                        }
                        // j = j + 500;
                        ViewBag.details    = user._user;
                        ViewBag.Count      = user._user.Count() + j;
                        ViewBag.TotalCount = user.count;
                        ViewBag.ApiDomain  = _appSettings.ApiDomain;
                        ViewBag.Domain     = _appSettings.Domain;
                        return(View("ManageUser"));
                    }
                }
                else if (param == "Next")
                {
                    j = j + 500;
                    return(RedirectToAction("ManageUser"));
                }
                else
                {
                    j = j - 500;
                    return(RedirectToAction("ManageUser"));
                }



                //HttpResponseMessage response = await WebApiReq.GetReq("/api/User/GetUserAdmin", "", "", _appSettings.ApiDomain);
                //if (response.IsSuccessStatusCode)
                //{
                //    user = await response.Content.ReadAsAsync<List<Domain.Socioboard.Models.User>>();

                //}
                //ViewBag.details = user;
                //ViewBag.ApiDomain = _appSettings.ApiDomain;
                //ViewBag.Domain = _appSettings.Domain;
                //return View("ManageUser");
            }


            //return Json(user);
        }
        public static string ComposeLinkedInMessage(string ImageUrl, long userid, string comment, string ProfileId, string imagepath, Domain.Socioboard.Models.LinkedInAccount _objLinkedInAccount, Model.DatabaseRepository dbr, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            string json = "";
            var    img  = "";

            Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = _objLinkedInAccount;
            oAuthLinkedIn _oauth = new oAuthLinkedIn();

            _oauth.ConsumerKey    = AppSettings.LinkedinConsumerKey;
            _oauth.ConsumerSecret = AppSettings.LinkedinConsumerSecret;
            _oauth.Token          = _LinkedInAccount.OAuthToken;
            string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json";


            if (string.IsNullOrEmpty(ImageUrl))
            {
                json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, comment);
            }
            else
            {
                json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, comment, ImageUrl);
            }

            if (!string.IsNullOrEmpty(json))
            {
                apiHitsCount++;
                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                //schmessage.url = json;
                dbr.Update <ScheduledMessage>(schmessage);
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Scheduled";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Successfully";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return("posted");
                }
                else
                {
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return("posted");
                }
            }
            else
            {
                apiHitsCount = MaxapiHitsCount;
                json         = "Message not posted";
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return(json);
                }
                else
                {
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return(json);
                }
            }
        }
Пример #5
0
        public async Task <ActionResult> Active(string id, string Token)
        {
            string res = string.Empty;
            List <KeyValuePair <string, string> > Parameters = new List <KeyValuePair <string, string> >();

            Parameters.Add(new KeyValuePair <string, string>("Id", id));
            Parameters.Add(new KeyValuePair <string, string>("Token", Token));
            HttpResponseMessage response = await WebApiReq.PostReq("/api/User/VerifyEmail", Parameters, "", "", _appSettings.ApiDomain);

            HttpResponseMessage userresponse = await WebApiReq.GetReq("/api/User/GetUser?Id=" + id, "", "", _appSettings.ApiDomain);

            try
            {
                if (response.IsSuccessStatusCode)
                {
                    //res = await response.Content.ReadAsStringAsync();
                    //TempData["Error"] = res;
                    //return RedirectToAction("index", "index");
                    if (userresponse.IsSuccessStatusCode)
                    {
                        string package = string.Empty;
                        User   user    = await userresponse.Content.ReadAsAsync <User>();

                        if (user != null)
                        {
                            HttpContext.Session.SetObjectAsJson("User", user);
                        }
                        else
                        {
                            return(RedirectToAction("index", "index"));
                        }


                        List <KeyValuePair <string, string> > Parameter = new List <KeyValuePair <string, string> >();
                        if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Free)
                        {
                            package = "Free";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Deluxe)
                        {
                            package = "Deluxe";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Premium)
                        {
                            package = "Premium";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Topaz)
                        {
                            package = "Topaz";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Platinum)
                        {
                            package = "Platinum";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Gold)
                        {
                            package = "Gold";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Ruby)
                        {
                            package = "Ruby";
                        }
                        else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Standard)
                        {
                            package = "Standard";
                        }

                        if (package != "Free")
                        {
                            Parameter.Add(new KeyValuePair <string, string>("packagename", package));
                            HttpResponseMessage respons = await WebApiReq.PostReq("/api/PaymentTransaction/GetPackage", Parameter, "", "", _appSettings.ApiDomain);

                            if (respons.IsSuccessStatusCode)
                            {
                                try
                                {
                                    if ((user.PayPalAccountStatus == Domain.Socioboard.Enum.PayPalAccountStatus.notadded || user.PayPalAccountStatus == Domain.Socioboard.Enum.PayPalAccountStatus.inprogress) && (user.AccountType != Domain.Socioboard.Enum.SBAccountType.Free))
                                    {
                                        Domain.Socioboard.Models.Package _Package = await respons.Content.ReadAsAsync <Domain.Socioboard.Models.Package>();

                                        HttpContext.Session.SetObjectAsJson("Package", _Package);
                                        if (user.PaymentType == Domain.Socioboard.Enum.PaymentType.paypal)
                                        {
                                            HttpContext.Session.SetObjectAsJson("paymentsession", true);
                                            return(Redirect(Helpers.Payment.RecurringPaymentWithPayPal(_Package.amount, _Package.packagename, user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", _appSettings.PaypalURL)));
                                        }
                                        else
                                        {
                                            HttpContext.Session.SetObjectAsJson("paymentsession", true);
                                            return(RedirectToAction("paymentWithPayUMoney", "Index", new { contesnt = false }));
                                        }
                                    }
                                    else
                                    {
                                        return(RedirectToAction("Index", "Home"));
                                    }
                                }
                                catch (Exception ex) { }
                            }
                        }
                        else
                        {
                            List <KeyValuePair <string, string> > _Parameters = new List <KeyValuePair <string, string> >();
                            _Parameters.Add(new KeyValuePair <string, string>("userId", user.Id.ToString()));
                            HttpResponseMessage _response = await WebApiReq.PostReq("/api/User/UpdateFreeUser", _Parameters, "", "", _appSettings.ApiDomain);

                            if (response.IsSuccessStatusCode)
                            {
                                try
                                {
                                    Domain.Socioboard.Models.User _user = await _response.Content.ReadAsAsync <Domain.Socioboard.Models.User>();

                                    HttpContext.Session.SetObjectAsJson("User", _user);
                                    return(RedirectToAction("Index", "Home"));
                                }
                                catch { }
                            }
                        }
                        return(RedirectToAction("index", "index"));
                    }
                }
                else
                {
                    TempData["Error"] = "Error while hiting api";
                    return(RedirectToAction("index", "index"));
                }
                return(RedirectToAction("index", "index"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("index", "index"));
            }
        }
Пример #6
0
        public static string ComposeLinkedInMessage(string ImageUrl, long userid, string comment, string ProfileId, string imagepath, Domain.Socioboard.Models.LinkedInAccount _objLinkedInAccount, Model.DatabaseRepository dbr, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            string json = "";
            var    img  = "";

            Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount = _objLinkedInAccount;
            oAuthLinkedIn _oauth = new oAuthLinkedIn();

            _oauth.ConsumerKey    = AppSettings.LinkedinConsumerKey;
            _oauth.ConsumerSecret = AppSettings.LinkedinConsumerSecret;
            _oauth.Token          = _LinkedInAccount.OAuthToken;
            string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json";

            //try
            //{
            //    var client = new ImgurClient(AppSettings.imgurClientId, AppSettings.imgurClientSecret);
            //    var endpoint = new ImageEndpoint(client);
            //    IImage image;
            //    using (var fs = new FileStream(ImageUrl, FileMode.Open))
            //    {
            //        image = endpoint.UploadImageStreamAsync(fs).GetAwaiter().GetResult();
            //    }
            //    img = image.Link;
            //}
            //catch (Exception)
            //{
            //    img = ImageUrl;
            //}

            if (string.IsNullOrEmpty(ImageUrl))
            {
                json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, comment);
            }
            else
            {
                //var client = new ImgurClient("5f1ad42ec5988b7", "f3294c8632ef8de6bfcbc46b37a23d18479159c5");
                //var endpoint = new ImageEndpoint(client);
                //IImage image;
                //using (var fs = new FileStream(imagepath, FileMode.Open))
                //{
                //    image = endpoint.UploadImageStreamAsync(fs).GetAwaiter().GetResult();
                //}

                //var imgs = image.Link;
                json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, comment, ImageUrl);
            }

            if (!string.IsNullOrEmpty(json))
            {
                apiHitsCount++;
                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                //schmessage.url = json;
                dbr.Update <ScheduledMessage>(schmessage);
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Scheduled";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Successfully";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return("posted");
                }
                else
                {
                    //if (_user.scheduleSuccessUpdates)
                    //{
                    //    string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    //}
                    return("posted");
                }
            }
            else
            {
                apiHitsCount = MaxapiHitsCount;
                json         = "Message not posted";
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return(json);
                }
                else
                {
                    //if (_user.scheduleFailureUpdates)
                    //{
                    //    string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    //}
                    return(json);
                }
            }
        }
 public static void PostLinkedInMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.LinkedInAccount _LinkedInAccount, Domain.Socioboard.Models.User _user)
 {
     try
     {
         DatabaseRepository dbr = new DatabaseRepository();
         if (_LinkedInAccount != null && _LinkedInAccount.IsActive)
         {
             string linkedindata = ComposeLinkedInMessage(schmessage.url, schmessage.userId, schmessage.shareMessage, _LinkedInAccount.LinkedinUserId, schmessage.picUrl, _LinkedInAccount, dbr, schmessage, _user);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
     }
 }
        public static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            string ret = "";
            var    dbr = new DatabaseRepository();

            try
            {
                var pageAccessToken = FacebookApiHelper.GetPageAccessToken(fbUserId, accessToken, string.Empty);
                var response        = FacebookApiHelper.PublishPostOnPage(pageAccessToken, fbUserId, message,
                                                                          imagePath, link);

                var isPublished = response.Contains("id");

                // if (isPublished)
                {
                    schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                    dbr.Update(schmessage);
                    var notify        = new Notifications();
                    var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                    if (notifications == null)
                    {
                        notify.MsgId            = schmessage.id;
                        notify.MsgStatus        = "Scheduled";
                        notify.notificationtime = schmessage.localscheduletime;
                        notify.NotificationType = "Schedule Successfully";
                        notify.ReadOrUnread     = "Unread";
                        notify.UserId           = userId;
                        dbr.Add(notify);
                        if (_user.scheduleSuccessUpdates)
                        {
                            var sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.error;
                dbr.Update(schmessage);
                apiHitsCount = MaxapiHitsCount;
                var notify        = new Notifications();
                var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (notifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userId;
                    dbr.Add(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        var falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
            }
            return(ret);
        }
Пример #9
0
        public static Domain.Socioboard.Models.YoutubeGroupInvite InviteGroupMember(Int64 userId, string emailId, Helper.AppSettings settings, ILogger _logger, Model.DatabaseRepository dbr)
        {
            YoutubeGroupInvite _objGrp = new YoutubeGroupInvite();
            IList <Domain.Socioboard.Models.User> lstUser = new List <User>();
            IList <Domain.Socioboard.Models.YoutubeGroupInvite> lstGrpUser = new List <YoutubeGroupInvite>();
            Thread getSbUser = new Thread(() =>
            {
                lstUser = lstUserSB(userId, emailId, dbr);
            }); getSbUser.Start();
            Thread getYtGrpUser = new Thread(() =>
            {
                lstGrpUser = lstGrpUserYt(userId, dbr);
            }); getYtGrpUser.Start();

            getSbUser.Join();
            getYtGrpUser.Join();

            Domain.Socioboard.Models.User _SBUser       = lstUser.FirstOrDefault(t => t.Id == userId);
            Domain.Socioboard.Models.User _SBUserInvite = lstUser.FirstOrDefault(t => t.EmailId == emailId);

            Domain.Socioboard.Models.YoutubeGroupInvite _grpOwner  = lstGrpUser.FirstOrDefault(t => t.UserId == userId);
            Domain.Socioboard.Models.YoutubeGroupInvite _grpInvMem = lstGrpUser.FirstOrDefault(t => t.SBEmailId == emailId);

            if (_grpOwner == null)
            {
                _objGrp.UserId       = _SBUser.Id;
                _objGrp.Owner        = true;
                _objGrp.OwnerName    = _SBUser.FirstName + " " + _SBUser.LastName;
                _objGrp.Active       = true;
                _objGrp.SBUserName   = _SBUser.FirstName + " " + _SBUser.LastName;
                _objGrp.SBEmailId    = _SBUser.EmailId;
                _objGrp.OwnerEmailid = _SBUser.EmailId;
                if (_SBUser.ProfilePicUrl == null || _SBUser.ProfilePicUrl == "")
                {
                    _objGrp.SBProfilePic = "https://i.imgur.com/zqN47Qp.png";
                }
                else
                {
                    _objGrp.SBProfilePic = _SBUser.ProfilePicUrl;
                }
                _objGrp.AccessSBUserId = userId;
                dbr.Add(_objGrp);
            }

            if (_SBUserInvite != null && _grpInvMem == null)
            {
                _objGrp.UserId       = _SBUserInvite.Id;
                _objGrp.Owner        = false;
                _objGrp.OwnerName    = _SBUser.FirstName + " " + _SBUser.LastName;
                _objGrp.OwnerEmailid = _SBUser.EmailId;
                _objGrp.Active       = false;
                _objGrp.SBUserName   = _SBUserInvite.FirstName + " " + _SBUserInvite.LastName;
                _objGrp.SBEmailId    = _SBUserInvite.EmailId;
                if (_SBUserInvite.ProfilePicUrl == null || _SBUserInvite.ProfilePicUrl == "")
                {
                    _objGrp.SBProfilePic = "https://i.imgur.com/zqN47Qp.png";
                }
                else
                {
                    _objGrp.SBProfilePic = _SBUserInvite.ProfilePicUrl;
                }
                _objGrp.AccessSBUserId       = userId;
                _objGrp.EmailValidationToken = SBHelper.RandomString(35);
                dbr.Add(_objGrp);
                return(_objGrp);
            }
            else if (_SBUserInvite == null && _grpInvMem == null)
            {
                _objGrp.UserId               = 0;
                _objGrp.Owner                = false;
                _objGrp.OwnerName            = _SBUser.FirstName + " " + _SBUser.LastName;
                _objGrp.OwnerEmailid         = _SBUser.EmailId;
                _objGrp.Active               = false;
                _objGrp.SBUserName           = "******";
                _objGrp.SBEmailId            = emailId;
                _objGrp.SBProfilePic         = "https://i.imgur.com/zqN47Qp.png";
                _objGrp.EmailValidationToken = SBHelper.RandomString(35);
                _objGrp.AccessSBUserId       = userId;
                dbr.Add(_objGrp);
                return(_objGrp);
            }

            else if (_grpInvMem.Active == false)
            {
                return(_grpInvMem);
            }
            else
            {
                return(null);
            }
        }
 public static void PostFacebookMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.Facebookaccounts _facebook, Domain.Socioboard.Models.User _user)
 {
     try
     {
         if (_facebook != null)
         {
             if (_facebook.IsActive)
             {
                 if (schmessage.scheduleTime <= DateTime.UtcNow)
                 {
                     string data = ComposeMessage(_facebook.FbProfileType, _facebook.AccessToken, _facebook.FbUserId, schmessage.shareMessage, schmessage.profileId, schmessage.userId, schmessage.url, schmessage.link, schmessage, _user);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
 public static void PostDaywiseFacebookMessage(Domain.Socioboard.Models.DaywiseSchedule schmessage, Domain.Socioboard.Models.Facebookaccounts _facebook, Domain.Socioboard.Models.User _user)
 {
     try
     {
         if (_facebook != null)
         {
             if (_facebook.IsActive)
             {
                 string   day  = DateTime.Now.DayOfWeek.ToString();
                 TimeSpan time = DateTime.Now.TimeOfDay;
                 //TimeSpan tv = TimeSpan.Parse(schmessage.localscheduletime);
                 //TimeSpan.Compare(time, tv);
                 TimeSpan dbtimeval = Convert.ToDateTime(schmessage.localscheduletime).TimeOfDay;//schmessage.localscheduletime
                 if (schmessage.scheduleTime <= DateTime.Now && dbtimeval <= time)
                 {
                     var selectDayObject = JsonConvert.DeserializeObject <List <string> >(schmessage.weekdays);
                     if (selectDayObject.Contains(DateTime.Now.DayOfWeek.ToString()))
                     {
                         string data = DaywiseComposeMessage(_facebook.FbProfileType, _facebook.AccessToken, _facebook.FbUserId, schmessage.shareMessage, schmessage.profileId, schmessage.userId, schmessage.url, schmessage.link, schmessage, _user);
                     }
                     else
                     {
                         schmessage.scheduleTime = DateTimeHelper.GetNextScheduleDate(selectDayObject, schmessage.scheduleTime);
                         if (schmessage.scheduleTime.Date == DateTime.Today)
                         {
                             schmessage.scheduleTime = schmessage.scheduleTime.AddDays(7);
                         }
                         var dbr = new DatabaseRepository();
                         dbr.Update(schmessage);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
        public static string DaywiseComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.DaywiseSchedule schmessage, Domain.Socioboard.Models.User _user)
        {
            string ret = "";
            var    dbr = new DatabaseRepository();

            try
            {
                var pageAccessToken = FacebookApiHelper.GetPageAccessToken(fbUserId, accessToken, string.Empty);
                var response        = FacebookApiHelper.PublishPostOnPage(pageAccessToken, fbUserId, message,
                                                                          imagePath, link);

                var isPublished = response.Contains("id");

                if (isPublished)
                {
                    var selectDayObject = JsonConvert.DeserializeObject <List <string> >(schmessage.weekdays);

                    schmessage.scheduleTime = DateTimeHelper.GetNextScheduleDate(selectDayObject, schmessage.scheduleTime);

                    if (schmessage.scheduleTime.Date == DateTime.Today)
                    {
                        schmessage.scheduleTime = schmessage.scheduleTime.AddDays(7);
                    }

                    dbr.Update(schmessage);
                    var notify        = new Notifications();
                    var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                    if (notifications == null)
                    {
                        notify.MsgId            = schmessage.id;
                        notify.MsgStatus        = "Scheduled";
                        notify.notificationtime = schmessage.localscheduletime.ToString();
                        notify.NotificationType = "Schedule Successfully";
                        notify.ReadOrUnread     = "Unread";
                        notify.UserId           = userId;
                        dbr.Add(notify);
                        if (_user.scheduleSuccessUpdates)
                        {
                            var sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime.ToString(), true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
                var notify        = new Notifications();
                var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (notifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime.ToString();
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userId;
                    dbr.Add(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime.ToString(), false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
            }
            return(ret);
        }
        public static string ComposeLinkedInCompanyPagePost(string ImageUrl, long userid, string comment, string LinkedinPageId, Model.DatabaseRepository dbr, Domain.Socioboard.Models.LinkedinCompanyPage objLinkedinCompanyPage, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            string json = "";

            Domain.Socioboard.Models.LinkedinCompanyPage objlicompanypage = objLinkedinCompanyPage;
            oAuthLinkedIn Linkedin_oauth = new oAuthLinkedIn();

            Linkedin_oauth.ConsumerKey    = AppSettings.LinkedinConsumerKey;
            Linkedin_oauth.ConsumerSecret = AppSettings.LinkedinConsumerSecret;
            Linkedin_oauth.Verifier       = objlicompanypage.OAuthVerifier;
            Linkedin_oauth.TokenSecret    = objlicompanypage.OAuthSecret;
            Linkedin_oauth.Token          = objlicompanypage.OAuthToken;
            Linkedin_oauth.Id             = objlicompanypage.LinkedinPageId;
            Linkedin_oauth.FirstName      = objlicompanypage.LinkedinPageName;
            Company company = new Company();

            if (string.IsNullOrEmpty(ImageUrl))
            {
                json = company.SetPostOnPage(Linkedin_oauth, objlicompanypage.LinkedinPageId, comment);
            }
            else
            {
                //var client = new ImgurClient("5f1ad42ec5988b7", "f3294c8632ef8de6bfcbc46b37a23d18479159c5");
                //var endpoint = new ImageEndpoint(client);
                //IImage image;
                //using (var fs = new FileStream(ImageUrl, FileMode.Open))
                //{
                //    image = endpoint.UploadImageStreamAsync(fs).GetAwaiter().GetResult();
                //}

                //var imgs = image.Link;
                json = company.SetPostOnPageWithImage(Linkedin_oauth, objlicompanypage.LinkedinPageId, ImageUrl, comment);
            }
            if (!string.IsNullOrEmpty(json))
            {
                apiHitsCount++;
                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                //schmessage.url = json;
                dbr.Update <ScheduledMessage>(schmessage);
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Scheduled";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Successfully";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return("posted");
                }
                else
                {
                    //if (_user.scheduleSuccessUpdates)
                    //{
                    //    string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    //}
                    return("posted");
                }
            }
            else
            {
                apiHitsCount = MaxapiHitsCount;
                json         = "Message not posted";
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                    return(json);
                }
                else
                {
                    //if (_user.scheduleFailureUpdates)
                    //{
                    //    string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    //}
                    return(json);
                }
            }
        }
        public static void PostLinkedInCompanyPageMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.LinkedinCompanyPage _LinkedinCompanyPage, Domain.Socioboard.Models.User _user)
        {
            try
            {
                DatabaseRepository dbr = new DatabaseRepository();

                //if (_LinkedinCompanyPage.SchedulerUpdate.AddHours(1) <= DateTime.UtcNow)
                //{
                if (_LinkedinCompanyPage != null)
                {
                    if (_LinkedinCompanyPage.IsActive)
                    {
                        //if (apiHitsCount < MaxapiHitsCount)
                        //{
                        if (schmessage.scheduleTime <= DateTime.UtcNow)
                        {
                            string linkedindata = ComposeLinkedInCompanyPagePost(schmessage.url, schmessage.userId, schmessage.shareMessage, _LinkedinCompanyPage.LinkedinPageId, dbr, _LinkedinCompanyPage, schmessage, _user);
                            if (!string.IsNullOrEmpty(linkedindata))
                            {
                                apiHitsCount++;
                            }
                        }
                        //}
                        //else
                        //{
                        //    apiHitsCount = 0;
                        //}
                    }
                    else
                    {
                        apiHitsCount = 0;
                    }
                }
                //}
                //else
                //{
                //    apiHitsCount = 0;
                //}
            }
            catch (Exception exs)
            {
                apiHitsCount = MaxapiHitsCount;
            }
        }
Пример #15
0
        public static string ComposeTwitterMessage(string message, string profileid, long userid, string picurl, bool isScheduled, DatabaseRepository dbr, Domain.Socioboard.Models.TwitterAccount TwitterAccount, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            bool   rt  = false;
            string ret = "";
            string str = "Message posted";

            if (message.Length > 140)
            {
                message = message.Substring(0, 135);
            }
            Domain.Socioboard.Models.TwitterAccount objTwitterAccount = TwitterAccount;
            oAuthTwitter OAuthTwt = new oAuthTwitter(AppSettings.twitterConsumerKey, AppSettings.twitterConsumerScreatKey, AppSettings.twitterRedirectionUrl);

            OAuthTwt.AccessToken       = objTwitterAccount.oAuthToken;
            OAuthTwt.AccessTokenSecret = objTwitterAccount.oAuthSecret;
            OAuthTwt.TwitterScreenName = objTwitterAccount.twitterScreenName;
            OAuthTwt.TwitterUserId     = objTwitterAccount.twitterUserId;

            Tweet twt = new Tweet();

            if (!string.IsNullOrEmpty(picurl))
            {
                try
                {
                    PhotoUpload ph  = new PhotoUpload();
                    string      res = string.Empty;
                    rt = ph.NewTweet(picurl, message, OAuthTwt, ref res);
                }
                catch (Exception ex)
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }
            else
            {
                try
                {
                    JArray post = twt.Post_Statuses_Update(OAuthTwt, message);
                    ret = post[0]["id_str"].ToString();
                }
                catch (Exception ex)
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }

            if (!string.IsNullOrEmpty(ret) || rt == true)
            {
                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                //schmessage.url = ret;
                dbr.Update <ScheduledMessage>(schmessage);
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Scheduled";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Successfully";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
                else
                {
                    //if (_user.scheduleSuccessUpdates)
                    //{
                    //    string sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    //}
                }
            }
            else
            {
                str = "Message not posted";
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userid;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
                else
                {
                    //if (_user.scheduleFailureUpdates)
                    //{
                    //    string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    //}
                }
            }

            return(str);
        }
Пример #16
0
 public static void PostTwitterMessage(Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.TwitterAccount _TwitterAccount, Domain.Socioboard.Models.User _user)
 {
     try
     {
         DatabaseRepository dbr = new DatabaseRepository();
         //if (_TwitterAccount.SchedulerUpdate.AddMinutes(15) <= DateTime.UtcNow)
         //{
         if (_TwitterAccount != null)
         {
             if (_TwitterAccount.isActive)
             {
                 //if (apiHitsCount < MaxapiHitsCount)
                 //{
                 if (schmessage.scheduleTime <= DateTime.UtcNow)
                 {
                     string twitterdata = ComposeTwitterMessage(schmessage.shareMessage, schmessage.profileId, schmessage.userId, schmessage.url, false, dbr, _TwitterAccount, schmessage, _user);
                     if (!string.IsNullOrEmpty(twitterdata) && twitterdata != "Message not posted")
                     {
                         apiHitsCount++;
                     }
                     else if (twitterdata == "Message not posted")
                     {
                         _TwitterAccount.isActive = false;
                         dbr.Update <TwitterAccount>(_TwitterAccount);
                     }
                 }
                 //}
                 //_TwitterAccount.lastUpdate = DateTime.UtcNow;
                 //dbr.Update<Domain.Socioboard.Models.TwitterAccount>(_TwitterAccount);
             }
             else
             {
                 // apiHitsCount = MaxapiHitsCount;
             }
         }
         //}
         //else
         //{
         //    apiHitsCount = 0;
         //}
     }
     catch (Exception ex)
     {
         apiHitsCount = MaxapiHitsCount;
     }
 }