public bool AddOrUpdateSnsTokenForAccount(Account account, string snsToken, MobilePlatformType mobilePlatform, DateTime?lastLoginDate = null, bool isLoggedIn = true,
                                                  bool isActive = true, string endpointArn = null)
        {
            var endpoint = DB.SNSEndpoints.FirstOrDefault(e => e.SNSToken == snsToken);

            if (endpoint == null)
            {
                return(CreateSnsEndPointForAccount(account, snsToken, mobilePlatform, out endpoint, lastLoginDate, isLoggedIn, isActive));
            }
            else
            {
                endpoint.Account            = account;
                endpoint.SNSToken           = snsToken;
                endpoint.MobilePlatformType = mobilePlatform;
                if (lastLoginDate.HasValue)
                {
                    endpoint.LastLoginDate = lastLoginDate.Value;
                }
                endpoint.IsLoggedIn = isLoggedIn;
                endpoint.IsActive   = isActive;

                try
                {
                    DB.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    ExceptionHelper.Log(ex);
                    return(false);
                }
            }
        }
        public bool CreateSnsEndPointForAccount(Account account, string snsToken, MobilePlatformType mobilePlatform, out SNSEndpoint snsEndpoint,
                                                DateTime?lastLoginDate = null, bool isLoggedIn = true, bool isActive = true)
        {
            snsEndpoint = new SNSEndpoint
            {
                Account            = account,
                CreateDate         = DateTime.Now,
                IsActive           = isActive,
                IsLoggedIn         = isLoggedIn,
                LastLoginDate      = lastLoginDate,
                MobilePlatformType = mobilePlatform,
                SNSToken           = snsToken,
                SnsEndpointAuthKey = account.CobrandToUse.CobrandSettings.CobrandAuthKey
            };

            try
            {
                DB.SNSEndpoints.Add(snsEndpoint);
                DB.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionHelper.Log(ex);
                return(false);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MobilePlatform" /> class.
 /// </summary>
 /// <param name="deviceName">Optional field, added to help with device detection using device atlas. This is equivalent of a.DeviceName field passed in from Mobile SDK .</param>
 /// <param name="deviceType">deviceType (required).</param>
 /// <param name="platformType">platformType (required).</param>
 /// <param name="version">If not specified - all activities with any platformVersion will be evaluated. If specified - only activities with the same platformVersion will be evaluated. .</param>
 public MobilePlatform(string deviceName = default(string), DeviceType deviceType = default(DeviceType), MobilePlatformType platformType = default(MobilePlatformType), string version = default(string))
 {
     this.DeviceType   = deviceType;
     this.PlatformType = platformType;
     this.DeviceName   = deviceName;
     this.Version      = version;
 }