/// <getUserDetails> /// Get user details by Google Account id. /// </summary> /// <param name="gaUserId">Id of google account(String)</param> /// <returns>Return object of Google analytic class.(Domein.GoogleAnalyticsAccount)</returns> public Domain.Socioboard.Domain.GoogleAnalyticsAccount getUserDetails(string gaUserId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //Proceed action to get details of account by Google account Id. NHibernate.IQuery query = session.CreateQuery("from GoogleAnalyticsAccount where GaAccountId = :gaUserId"); query.SetParameter("gaUserId", gaUserId); List <Domain.Socioboard.Domain.GoogleAnalyticsAccount> lst = new List <Domain.Socioboard.Domain.GoogleAnalyticsAccount>(); foreach (Domain.Socioboard.Domain.GoogleAnalyticsAccount item in query.Enumerable()) { lst.Add(item); break; } Domain.Socioboard.Domain.GoogleAnalyticsAccount fbacc = lst[0]; return(fbacc); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } //End Transaction } //End Session }
public IHttpActionResult GetGroupGoogleAnalytics(string GroupId, string UserId) { Guid grpId = Guid.Empty; try { grpId = Guid.Parse(GroupId); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); return(BadRequest("Invalid GroupId")); } List <Domain.Socioboard.Domain.GroupProfile> lstGroupProfiles = grpProfilesRepo.GetAllGroupProfilesByProfileType(grpId, "googleanalytics"); List <Domain.Socioboard.Domain.GoogleAnalyticsAccount> lstGoogleAnalyticsAccount = new List <Domain.Socioboard.Domain.GoogleAnalyticsAccount>(); GoogleAnalyticsAccountRepository _GoogleAnalyticsAccountRepository = new GoogleAnalyticsAccountRepository(); foreach (var profile in lstGroupProfiles) { try { Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount = _GoogleAnalyticsAccountRepository.getGoogleAnalyticsAccountDetailsById(profile.ProfileId, Guid.Parse(UserId)); lstGoogleAnalyticsAccount.Add(_GoogleAnalyticsAccount); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } } return(Ok(lstGoogleAnalyticsAccount)); }
public string GetGooglePlusAccountDetailsById(string UserId, string GAId) { Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); try { _GoogleAnalyticsAccount = objGoogleAnalyticsAccountRepository.getGoogleAnalyticsAccountDetailsById(GAId, Guid.Parse(UserId)); } catch (Exception ex) { _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); } return new JavaScriptSerializer().Serialize(_GoogleAnalyticsAccount); }
/// <getGoogelAnalyticsAccountDetailsById> /// Get the details of googel analytics account by Google account id and user id. /// </summary> /// <param name="gauserid">Id of goole accont(String)</param> /// <param name="userId">Id of user(Guid)</param> /// <returns>Return object of Google analytic class.(Domein.GoogleAnalyticsAccount)</returns> public Domain.Socioboard.Domain.GoogleAnalyticsAccount getGoogleAnalyticsAccountDetailsById(string gauserid, Guid userId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //Proceed action, to get deatils of account NHibernate.IQuery query = session.CreateQuery("from GoogleAnalyticsAccount where GaProfileId = :GaAccountId and UserId=:userId") .SetParameter("GaAccountId", gauserid) .SetParameter("userId", userId); Domain.Socioboard.Domain.GoogleAnalyticsAccount result = (Domain.Socioboard.Domain.GoogleAnalyticsAccount)query.UniqueResult(); return(result); }//End Session }
public string GetGooglePlusAccountDetailsById(string UserId, string GAId) { Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); try { _GoogleAnalyticsAccount = objGoogleAnalyticsAccountRepository.getGoogleAnalyticsAccountDetailsById(GAId, Guid.Parse(UserId)); } catch (Exception ex) { _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); } return(new JavaScriptSerializer().Serialize(_GoogleAnalyticsAccount)); }
/// <addGoogleAnalyticsUser> /// Add New Google Analytics User /// </summary> /// <param name="gaaccount">Set Values in a GoogleAnalyticsAccount Class Property and Pass the same Object of GoogleAnalyticsAccount Class.(Domain.GoogleAnalyticsAccount)</param> public void Add(Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to save data. session.Save(_GoogleAnalyticsAccount); transaction.Commit(); } //End Transaction } //End Session }
public IHttpActionResult GetGooglePlusAccountDetailsById(string ProfileId, string UserId) { Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); try { _GoogleAnalyticsAccount = objGoogleAnalyticsAccountRepository.getGoogleAnalyticsAccountDetailsById(ProfileId, Guid.Parse(UserId)); return(Ok(_GoogleAnalyticsAccount)); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); return(BadRequest("Worng Input")); } }
public IHttpActionResult GetGooglePlusAccountDetailsById(string ProfileId,string UserId) { Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); try { _GoogleAnalyticsAccount = objGoogleAnalyticsAccountRepository.getGoogleAnalyticsAccountDetailsById(ProfileId, Guid.Parse(UserId)); return Ok(_GoogleAnalyticsAccount); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); return BadRequest("Worng Input"); } }
public string AddAnalyticsProfiles(string GAProfiles, string UserId, string GroupId) { try { Analytics _Analytics = new Analytics(); List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = (List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles>)new JavaScriptSerializer().Deserialize(GAProfiles, typeof(List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles>)); Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount; foreach (var item in lstGoogleAnalyticsProfiles) { try { _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); _GoogleAnalyticsAccount.UserId = Guid.Parse(UserId); _GoogleAnalyticsAccount.EmailId = item.EmailId; _GoogleAnalyticsAccount.GaAccountId = item.AccountId; _GoogleAnalyticsAccount.GaAccountName = item.AccountName; _GoogleAnalyticsAccount.GaWebPropertyId = item.WebPropertyId; _GoogleAnalyticsAccount.GaProfileId = item.ProfileId; _GoogleAnalyticsAccount.GaProfileName = item.ProfileName; _GoogleAnalyticsAccount.AccessToken = item.AccessToken; _GoogleAnalyticsAccount.RefreshToken = item.RefreshToken; _GoogleAnalyticsAccount.WebsiteUrl = item.WebsiteUrl; string visits = string.Empty; string pageviews = string.Empty; try { string analytics = _Analytics.getAnalyticsData(item.ProfileId, "ga:visits,ga:pageviews", DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.UtcNow.ToString("yyyy-MM-dd"), item.AccessToken); JObject JData = JObject.Parse(analytics); visits = JData["totalsForAllResults"]["ga:visits"].ToString(); pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString(); } catch (Exception ex) { visits = "0"; pageviews = "0"; } _GoogleAnalyticsAccount.Views = Double.Parse(pageviews); _GoogleAnalyticsAccount.Visits = Double.Parse(visits); _GoogleAnalyticsAccount.ProfilePicUrl = ConfigurationManager.AppSettings["DomainName"] + "/Themes/" + ConfigurationManager.AppSettings["DefaultGroupName"] + "/Contents/img/analytics_img.png"; _GoogleAnalyticsAccount.IsActive = true; _GoogleAnalyticsAccount.EntryDate = DateTime.UtcNow; if (!_GoogleAnalyticsAccountRepository.checkGoogelAnalyticsUserExists(item.ProfileId, item.AccountId, Guid.Parse(UserId))) { _GoogleAnalyticsAccountRepository.Add(_GoogleAnalyticsAccount); } #region TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); if (!grpProfileRepo.checkProfileExistsingroup(Guid.Parse(GroupId), item.ProfileId)) { //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); //objTeamMemberProfile.ProfileId = item.ProfileId; //objTeamMemberProfile.ProfileName = item.ProfileName; //objTeamMemberProfile.ProfilePicUrl = ConfigurationManager.AppSettings["DomainName"] + "/Themes/Socioboard/Contents/img/analytics_img.png"; //objTeamMemberProfile.ProfileType = "googleanalytics"; //objTeamMemberProfile.Status = 1; //objTeamMemberProfile.StatusUpdateDate = DateTime.Now; //objTeamMemberProfile.TeamId = objTeam.Id; //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile(); grpProfile.Id = Guid.NewGuid(); grpProfile.EntryDate = DateTime.UtcNow; grpProfile.GroupId = Guid.Parse(GroupId); grpProfile.GroupOwnerId = Guid.Parse(UserId); grpProfile.ProfileId = item.ProfileId; grpProfile.ProfileType = "googleanalytics"; grpProfile.ProfileName = item.ProfileName; grpProfile.ProfilePic = ConfigurationManager.AppSettings["DomainName"] + "/Themes/" + ConfigurationManager.AppSettings["DefaultGroupName"] + "/Contents/img/analytics_img.png"; grpProfileRepo.AddGroupProfile(grpProfile); } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.ProfileType = "googleanalytics"; objSocialProfile.ProfileId = item.ProfileId; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion } catch (Exception ex) { logger.Error("AddAnalyticsProfiles = > " + ex.Message); } } } catch (Exception ex) { logger.Error("AddAnalyticsProfiles = > " + ex.Message); } return "added successfully"; }
public string AddAnalyticsProfiles(string GAProfiles, string UserId, string GroupId) { try { Analytics _Analytics = new Analytics(); List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = (List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles>) new JavaScriptSerializer().Deserialize(GAProfiles, typeof(List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles>)); Domain.Socioboard.Domain.GoogleAnalyticsAccount _GoogleAnalyticsAccount; foreach (var item in lstGoogleAnalyticsProfiles) { try { _GoogleAnalyticsAccount = new Domain.Socioboard.Domain.GoogleAnalyticsAccount(); _GoogleAnalyticsAccount.UserId = Guid.Parse(UserId); _GoogleAnalyticsAccount.EmailId = item.EmailId; _GoogleAnalyticsAccount.GaAccountId = item.AccountId; _GoogleAnalyticsAccount.GaAccountName = item.AccountName; _GoogleAnalyticsAccount.GaWebPropertyId = item.WebPropertyId; _GoogleAnalyticsAccount.GaProfileId = item.ProfileId; _GoogleAnalyticsAccount.GaProfileName = item.ProfileName; _GoogleAnalyticsAccount.AccessToken = item.AccessToken; _GoogleAnalyticsAccount.RefreshToken = item.RefreshToken; _GoogleAnalyticsAccount.WebsiteUrl = item.WebsiteUrl; string visits = string.Empty; string pageviews = string.Empty; try { string analytics = _Analytics.getAnalyticsData(item.ProfileId, "ga:visits,ga:pageviews", DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.UtcNow.ToString("yyyy-MM-dd"), item.AccessToken); JObject JData = JObject.Parse(analytics); visits = JData["totalsForAllResults"]["ga:visits"].ToString(); pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString(); } catch (Exception ex) { visits = "0"; pageviews = "0"; } _GoogleAnalyticsAccount.Views = Double.Parse(pageviews); _GoogleAnalyticsAccount.Visits = Double.Parse(visits); _GoogleAnalyticsAccount.ProfilePicUrl = ConfigurationManager.AppSettings["DomainName"] + "/Themes/" + ConfigurationManager.AppSettings["DefaultGroupName"] + "/Contents/img/analytics_img.png"; _GoogleAnalyticsAccount.IsActive = true; _GoogleAnalyticsAccount.EntryDate = DateTime.UtcNow; if (!_GoogleAnalyticsAccountRepository.checkGoogelAnalyticsUserExists(item.ProfileId, item.AccountId, Guid.Parse(UserId))) { _GoogleAnalyticsAccountRepository.Add(_GoogleAnalyticsAccount); } #region TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); if (!grpProfileRepo.checkProfileExistsingroup(Guid.Parse(GroupId), item.ProfileId)) { //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); //objTeamMemberProfile.ProfileId = item.ProfileId; //objTeamMemberProfile.ProfileName = item.ProfileName; //objTeamMemberProfile.ProfilePicUrl = ConfigurationManager.AppSettings["DomainName"] + "/Themes/Socioboard/Contents/img/analytics_img.png"; //objTeamMemberProfile.ProfileType = "googleanalytics"; //objTeamMemberProfile.Status = 1; //objTeamMemberProfile.StatusUpdateDate = DateTime.Now; //objTeamMemberProfile.TeamId = objTeam.Id; //objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile(); grpProfile.Id = Guid.NewGuid(); grpProfile.EntryDate = DateTime.UtcNow; grpProfile.GroupId = Guid.Parse(GroupId); grpProfile.GroupOwnerId = Guid.Parse(UserId); grpProfile.ProfileId = item.ProfileId; grpProfile.ProfileType = "googleanalytics"; grpProfile.ProfileName = item.ProfileName; grpProfile.ProfilePic = ConfigurationManager.AppSettings["DomainName"] + "/Themes/" + ConfigurationManager.AppSettings["DefaultGroupName"] + "/Contents/img/analytics_img.png"; grpProfileRepo.AddGroupProfile(grpProfile); } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.ProfileType = "googleanalytics"; objSocialProfile.ProfileId = item.ProfileId; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion } catch (Exception ex) { logger.Error("AddAnalyticsProfiles = > " + ex.Message); } } } catch (Exception ex) { logger.Error("AddAnalyticsProfiles = > " + ex.Message); } return("added successfully"); }