public JsonNetResult UpdateContactInfo(string phoneNumber, string email, string address1, string address2, string city, string state, string postalCode)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            //Make updates:
            accountSettings.ContactSettings.ContactInfo             = new ContactInfoModel();
            accountSettings.ContactSettings.ContactInfo.PhoneNumber = phoneNumber;
            accountSettings.ContactSettings.ContactInfo.Email       = email;
            accountSettings.ContactSettings.ContactInfo.Address1    = address1;
            accountSettings.ContactSettings.ContactInfo.Address2    = address2;
            accountSettings.ContactSettings.ContactInfo.City        = city;
            accountSettings.ContactSettings.ContactInfo.State       = state;
            accountSettings.ContactSettings.ContactInfo.PostalCode  = postalCode;

            var response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);

            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public JsonNetResult UpdateTheme(string themeName)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            var account = Common.GetAccountObject(accountNameKey);

            var response = new DataAccessResponseType();

            if (account.PaymentPlan.AllowThemes == false)
            {
                response = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Your account plan does not allow for additional or custom themes."
                };
            }
            else
            {
                var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

                //Make updates:
                accountSettings.Theme = themeName;

                response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);
            }


            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 3
0
        public JsonNetResult RefundPayment(string accountId, string chargeId, decimal refundAmount)
        {
            DataAccessResponseType response = null;

            if (string.IsNullOrEmpty(accountId))
            {
                response = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Cannot apply refunds on closed/null accounts."
                };
            }
            else
            {
                var user = AuthenticationCookieManager.GetAuthenticationCookie();


                if (response == null)
                {
                    var accountBillingServiceClient = new AccountBillingService.AccountBillingServiceClient();

                    try
                    {
                        accountBillingServiceClient.Open();
                        response = accountBillingServiceClient.RefundPayment(
                            accountId,
                            chargeId,
                            refundAmount,
                            AuthenticationCookieManager.GetAuthenticationCookie().Id,
                            PlatformAdminSite.AccountBillingService.RequesterType.PlatformUser, Common.SharedClientKey
                            );//,
                              //user.Id,
                              //PlatformAdminSite.AccountManagementService.RequesterType.PlatformUser).ToList();

                        //Close the connection
                        WCFManager.CloseConnection(accountBillingServiceClient);
                    }
                    catch (Exception e)
                    {
                        #region Manage Exception

                        string exceptionMessage = e.Message.ToString();

                        var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                        string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                        // Abort the connection & manage the exception
                        WCFManager.CloseConnection(accountBillingServiceClient, exceptionMessage, currentMethodString);

                        #endregion
                    }
                }
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 4
0
        public ActionResult RedisServers()
        {
            if (AuthenticationCookieManager.GetAuthenticationCookie().Role != "SuperAdmin")
            {
                return(Content("Sorry! Your princess is in another castle..."));
            }

            return(View());
        }
Ejemplo n.º 5
0
        public JsonNetResult Subscribe(string accountId, string planName, string frequencyMonths, string cardName, string cardNumber, string cvc, string expirationMonth, string expirationYear)
        {
            var response = new AccountManagementService.DataAccessResponseType();
            var accountManagementServiceClient = new AccountManagementService.AccountManagementServiceClient();

            try
            {
                //Get the ip address and call origin
                var ipAddress = Request.UserHostAddress;
                var origin    = "Web";

                accountManagementServiceClient.Open();

                response = accountManagementServiceClient.CreateSubscripton(
                    accountId,
                    planName,
                    frequencyMonths,
                    cardName,
                    cardNumber,
                    cvc,
                    expirationMonth,
                    expirationYear,
                    AuthenticationCookieManager.GetAuthenticationCookie().Id,
                    AccountManagementService.RequesterType.PlatformUser,
                    ipAddress,
                    origin, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(accountManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountManagementServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 6
0
        public override bool IsAuthenticated()
        {
            if (Context == null)
            {
                return(false);
            }
            string username = AuthenticationCookieManager.Load(Context);

            return(!string.IsNullOrEmpty(username));
        }
Ejemplo n.º 7
0
        public JsonNetResult UploadPhoto() //  HttpPostedFileBase file)     //  Object file)
        {
            var length = Request.ContentLength;
            var bytes  = new byte[length];

            Request.InputStream.Read(bytes, 0, length);

            var response = new DataAccessResponseType();
            var platformManagementServiceClient = new AccountManagementService.AccountManagementServiceClient();

            JsonNetResult jsonNetResult = new JsonNetResult();

            try
            {
                platformManagementServiceClient.Open();

                var user = AuthenticationCookieManager.GetAuthenticationCookie();

                response = platformManagementServiceClient.UpdateAccountUserProfilePhoto(
                    user.AccountID.ToString(),
                    user.Id,
                    bytes,
                    user.Id,
                    AccountAdminSite.AccountManagementService.RequesterType.Exempt, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(platformManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(platformManagementServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public JsonNetResult MarkNotificationRead(string notificationType, string notificationId)
        {
            var accountCommunicationServiceClient = new AccountCommunicationService.AccountCommunicationServiceClient();

            try
            {
                accountCommunicationServiceClient.Open();

                //Convert notification type to Enum
                NotificationType _convertedNotificationType = (NotificationType)Enum.Parse(typeof(NotificationType), notificationType);

                var response = accountCommunicationServiceClient.UpdateNotificationStatus(
                    _convertedNotificationType,
                    NotificationStatus.Read,
                    "Unread",
                    AuthenticationCookieManager.GetAuthenticationCookie().Id,
                    notificationId, Common.SharedClientKey
                    );

                //Close the connection
                WCFManager.CloseConnection(accountCommunicationServiceClient);

                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = response;

                return(jsonNetResult);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountCommunicationServiceClient, exceptionMessage, currentMethodString);

                #endregion

                JsonNetResult jsonNetErrorResult = new JsonNetResult();
                jsonNetErrorResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetErrorResult.Data       = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = WCFManager.UserFriendlyExceptionMessage
                };

                return(jsonNetErrorResult);
            }
        }
Ejemplo n.º 9
0
        public JsonNetResult TradeCredits(string toAccountId, int creditsAmount, string description)
        {
            var accountUser = AuthenticationCookieManager.GetAuthenticationCookie();
            var response    = new AccountAdminSite.AccountCommerceService.DataAccessResponseType();

            var accountCommerceServiceClient = new AccountCommerceService.AccountCommerceServiceClient();

            try
            {
                //Get the ip address and call origin
                var ipAddress = Request.UserHostAddress;
                var origin    = "Web";

                accountCommerceServiceClient.Open();
                response = accountCommerceServiceClient.TradeCredits(
                    accountUser.AccountID.ToString(),
                    toAccountId,
                    creditsAmount,
                    description,
                    accountUser.Id,
                    AccountAdminSite.AccountCommerceService.RequesterType.AccountUser,
                    ipAddress,
                    origin, Common.SharedClientKey
                    );

                //Close the connection
                WCFManager.CloseConnection(accountCommerceServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountCommerceServiceClient, exceptionMessage, currentMethodString);

                #endregion
            }



            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public JsonNetResult GetAccountSettings()
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            var accountSettngs = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = accountSettngs;

            return(jsonNetResult);
        }
Ejemplo n.º 11
0
        public JsonNetResult UpdateName(string firstName, string lastName)
        {
            var response = new DataAccessResponseType();
            var accountManagementServiceClient = new AccountManagementService.AccountManagementServiceClient();

            try
            {
                accountManagementServiceClient.Open();

                var user = AuthenticationCookieManager.GetAuthenticationCookie();

                response = accountManagementServiceClient.UpdateAccountUserFullName(
                    user.AccountID.ToString(),
                    user.Id,
                    firstName,
                    lastName,
                    user.Id,
                    RequesterType.Exempt, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(accountManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountManagementServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }


            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 12
0
        public JsonNetResult GetOtherAccounts()
        {
            List <UserAccount> response = null;

            try
            {
                var accountManagementServiceClient = new AccountManagementService.AccountManagementServiceClient();

                try
                {
                    accountManagementServiceClient.Open();
                    response = accountManagementServiceClient.GetAllAccountsForEmail(AuthenticationCookieManager.GetAuthenticationCookie().Email, Common.SharedClientKey).ToList();

                    //Close the connection
                    WCFManager.CloseConnection(accountManagementServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(accountManagementServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }

                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = response;

                return(jsonNetResult);
            }
            catch
            {
                // Use cookies instead
                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = AuthenticationCookieManager.GetAuthenticationCookie();

                return(jsonNetResult);
            }
        }
Ejemplo n.º 13
0
        public JsonNetResult RemoveSalesLeadLabel(int index)
        {
            var response = new ApplicationLeadsService.DataAccessResponseType();
            var applicationLeadsServiceClient = new ApplicationLeadsService.ApplicationLeadsServiceClient();

            var authCookie     = AuthenticationCookieManager.GetAuthenticationCookie();
            var accountNameKey = authCookie.AccountNameKey;
            var userId         = authCookie.Id.ToString();

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);
            var label           = accountSettings.SalesSettings.LeadLabels[index];

            try
            {
                applicationLeadsServiceClient.Open();
                response = applicationLeadsServiceClient.RemoveLabel(accountNameKey, label,
                                                                     userId,
                                                                     ApplicationLeadsService.RequesterType.AccountUser, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(applicationLeadsServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(applicationLeadsServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public JsonNetResult GetNotificationsByType(string notificationType, string notificationStatus)
        {
            var userId = AuthenticationCookieManager.GetAuthenticationCookie().Id;
            var accountCommunicationServiceClient = new AccountCommunicationService.AccountCommunicationServiceClient();

            try
            {
                accountCommunicationServiceClient.Open();

                //Convert notification type to Enum
                NotificationType _convertedNotificationType = (NotificationType)Enum.Parse(typeof(NotificationType), notificationType);

                //Convert notification status to Enum
                NotificationStatus _convertedNotificationStatus = (NotificationStatus)Enum.Parse(typeof(NotificationStatus), notificationStatus);

                var userNotifications = accountCommunicationServiceClient.GetAccountUserNotificationsByType(_convertedNotificationType, _convertedNotificationStatus, userId, Common.SharedClientKey).ToList();

                //Close the connection
                WCFManager.CloseConnection(accountCommunicationServiceClient);

                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = userNotifications;

                return(jsonNetResult);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountCommunicationServiceClient, exceptionMessage, currentMethodString);

                #endregion

                JsonNetResult jsonNetErrorResult = new JsonNetResult();
                jsonNetErrorResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetErrorResult.Data       = WCFManager.UserFriendlyExceptionMessage;

                return(jsonNetErrorResult);
            }
        }
Ejemplo n.º 15
0
        public JsonNetResult UpdatePlanVisibility(string paymentPlanName, bool isVisible)
        {
            var response = new AccountPaymentPlanService.DataAccessResponseType();
            var accountPaymentPlanServiceClient = new AccountPaymentPlanService.AccountPaymentPlanServiceClient();

            try
            {
                accountPaymentPlanServiceClient.Open();
                response = accountPaymentPlanServiceClient.UpdatePlanVisibility(
                    paymentPlanName,
                    isVisible,
                    AuthenticationCookieManager.GetAuthenticationCookie().Id,
                    PlatformAdminSite.AccountPaymentPlanService.RequesterType.PlatformUser, Common.SharedClientKey
                    );

                //Close the connection
                WCFManager.CloseConnection(accountPaymentPlanServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountPaymentPlanServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }


            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 16
0
        public JsonNetResult GenerateApiKey(string name, string description)
        {
            string response = null;
            var    applicationApiKeysServiceClient = new ApplicationApiKeysService.ApplicationApiKeysServiceClient();

            try
            {
                var authCookie     = AuthenticationCookieManager.GetAuthenticationCookie();
                var requesterId    = authCookie.Id;
                var accountNameKey = authCookie.AccountNameKey;

                applicationApiKeysServiceClient.Open();
                response = applicationApiKeysServiceClient.GenerateApiKey(accountNameKey, name, description,
                                                                          requesterId, ApplicationApiKeysService.RequesterType.AccountUser, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(applicationApiKeysServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(applicationApiKeysServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                //response.isSuccess = false;
                //response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public JsonNetResult UpdateShowAddress(bool showAddress)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            //Make updates:
            accountSettings.ContactSettings.ShowAddress = showAddress;

            var response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);

            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public JsonNetResult RemoveSalesAlertEmail(int index)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            //Make updates:
            accountSettings.SalesSettings.AlertEmails.RemoveAt(index);

            var response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);

            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 19
0
        public JsonNetResult DeleteGalleryImageForObject(string objectType, string objectId, string groupNameKey, string formatNameKey, int imageIndex)
        {
            var response = new ApplicationImagesService.DataAccessResponseType();

            #region Delete Image

            var user = AuthenticationCookieManager.GetAuthenticationCookie();

            try
            {
                var applicationImagesServicesClient = new ApplicationImagesServiceClient();
                response = applicationImagesServicesClient.DeleteGalleryImage(user.AccountID.ToString(), objectType, objectId, groupNameKey, formatNameKey, imageIndex, user.Id, ApplicationImagesService.RequesterType.AccountUser, Common.SharedClientKey);
            }
            catch (Exception e)
            {
                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
            }

            #endregion

            #region Handle Caching Expiration on Account image type

            if (objectType == "account")
            {
                //Expire accountimages cache
                RedisCacheKeys.AccountImages.Expire(user.AccountNameKey);
            }

            #endregion

            #region Handle Results

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);

            #endregion
        }
        public JsonNetResult UpdateUseSalesLeads(bool useSalesLeads)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            #region Make sure account plan allow for sales leads

            var account = Common.GetAccountObject(accountNameKey);

            if (useSalesLeads == true && account.PaymentPlan.AllowSalesLeads == false)
            {
                JsonNetResult jsonNetResultRestricted = new JsonNetResult();
                jsonNetResultRestricted.Formatting = Formatting.Indented;
                jsonNetResultRestricted.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResultRestricted.Data = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Account plan does not allow for sales leads"
                };

                return(jsonNetResultRestricted);
            }

            #endregion

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            //Make updates:
            accountSettings.SalesSettings.UseSalesLeads = useSalesLeads;
            if (!useSalesLeads)
            {
                accountSettings.SalesSettings.UseSalesAlerts = useSalesLeads;
            }

            var response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
        public static DataAccessResponseType UpdateAccountSettings_Internal(string accountNameKey, AccountSettingsDocumentModel accountSettingsDocumentModel)
        {
            var response = new AccountManagementService.DataAccessResponseType();

            var accountManagementServiceClient = new AccountManagementService.AccountManagementServiceClient();

            try
            {
                accountManagementServiceClient.Open();
                response = accountManagementServiceClient.UpdateAccountSettings(accountNameKey, accountSettingsDocumentModel,
                                                                                AuthenticationCookieManager.GetAuthenticationCookie().Id,
                                                                                AccountAdminSite.AccountManagementService.RequesterType.AccountUser, Common.SharedClientKey);

                //Close the connection
                WCFManager.CloseConnection(accountManagementServiceClient);
            }
            catch (Exception e)
            {
                #region Manage Exception

                string exceptionMessage = e.Message.ToString();

                var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                // Abort the connection & manage the exception
                WCFManager.CloseConnection(accountManagementServiceClient, exceptionMessage, currentMethodString);

                // Upate the response object
                response.isSuccess    = false;
                response.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                //response.ErrorMessages[0] = exceptionMessage;

                #endregion
            }

            return(response);
        }
        public JsonNetResult UpdateCustomDomain(string customDomain)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            var account = Common.GetAccountObject(accountNameKey);

            var response = new DataAccessResponseType();

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            //Make updates:
            accountSettings.CustomDomain = customDomain;

            response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);

            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 23
0
        public JsonNetResult ProcessImage(string imageId, string objectType, string objectId, string imageGroupNameKey, string imageFormatNameKey, string containerName, string imageFormat, string type, int quality, float top, float left, float right, float bottom, string title, string description, string tags, int brightness, int contrast, int saturation, int sharpness, bool sepia, bool polaroid, bool greyscale)
        {
            var response = new ApplicationImagesService.DataAccessResponseType();


            #region Generate Job Models

            var imageProcessingManifest = new ImageProcessingManifestModel
            {
                SourceContainerName = containerName,
                FileName            = imageId + "." + imageFormat,

                GroupTypeNameKey = objectType,
                ObjectId         = objectId,

                Type    = type,
                Quality = quality,

                GroupNameKey  = imageGroupNameKey,
                FormatNameKey = imageFormatNameKey,

                ImageId     = imageId,
                Title       = title,
                Description = description
            };


            var imageCropCoordinates = new ImageCropCoordinates
            {
                Top    = top,
                Left   = left,
                Right  = right,
                Bottom = bottom
            };

            var imageEnhancementInstructions = new ImageEnhancementInstructions();

            if (brightness != 0 || contrast != 0 || saturation != 0 || saturation != 0 || sharpness != 0 || sepia == true || polaroid == true || greyscale == true)
            {
                imageEnhancementInstructions.Brightness = brightness;
                imageEnhancementInstructions.Contrast   = contrast;
                imageEnhancementInstructions.Saturation = saturation;
                imageEnhancementInstructions.Sharpen    = sharpness;
                imageEnhancementInstructions.Sepia      = sepia;
                imageEnhancementInstructions.Greyscale  = greyscale;
                imageEnhancementInstructions.Polaroid   = polaroid;
            }
            else
            {
                imageEnhancementInstructions = null;
            }



            #endregion

            #region Submit Job

            var user    = AuthenticationCookieManager.GetAuthenticationCookie();
            var account = Common.GetAccountObject(user.AccountNameKey);

            try
            {
                var applicationImagesServicesClient = new ApplicationImagesServiceClient();
                response = applicationImagesServicesClient.ProcessImage(user.AccountID.ToString(), imageProcessingManifest, imageCropCoordinates, user.Id, ApplicationImagesService.RequesterType.AccountUser, imageEnhancementInstructions, Common.SharedClientKey);
            }
            catch (Exception e)
            {
                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
            }

            #endregion

            #region Handle Caching Expiration on Account image type

            if (objectType == "account")
            {
                //Expire accountimages cache
                RedisCacheKeys.AccountImages.Expire(user.AccountNameKey);
            }

            #endregion

            //Append account CDN url to Success message (newImageUrlPath)
            var storagePartition = CoreServices.PlatformSettings.StorageParitions.FirstOrDefault(partition => partition.Name == account.StoragePartition);
            response.SuccessMessage = "https://" + storagePartition.CDN + "/" + response.SuccessMessage;

            #region Handle Results

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);

            #endregion
        }
Ejemplo n.º 24
0
        public JsonNetResult GetNextInvoice(string accountId)
        {
            var     user    = AuthenticationCookieManager.GetAuthenticationCookie();
            Invoice invoice = null;

            #region (Plan A) Get data from Redis Cache

            /*
             * try
             * {
             *  IDatabase cache = CoreServiceSettings.RedisConnectionMultiplexers.AccountManager_Multiplexer.GetDatabase();
             *
             *  string hashKey = "accountbyid:" + accountId.ToString().Replace("-", "");
             *  string hashField = "creditcard";
             *
             *  var redisValue = cache.HashGet(hashKey, hashField);
             *
             *  if (redisValue.HasValue)
             *  {
             *      accountCreditCardInfo = JsonConvert.DeserializeObject<AccountCreditCardInfo>(redisValue);
             *  }
             * }
             * catch (Exception e)
             * {
             *  var error = e.Message;
             *  //TODO: Log: error message for Redis call
             * }*/

            #endregion

            if (invoice == null)
            {
                #region (Plan B) Get data from WCF

                var accountBillingServiceClient = new AccountBillingService.AccountBillingServiceClient();

                try
                {
                    accountBillingServiceClient.Open();
                    invoice = accountBillingServiceClient.GetUpcomingInvoice(
                        accountId, Common.SharedClientKey);//,
                    //user.Id,
                    //PlatformAdminSite.AccountManagementService.RequesterType.PlatformUser);

                    //Close the connection
                    WCFManager.CloseConnection(accountBillingServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(accountBillingServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = invoice;

            return(jsonNetResult);
        }
Ejemplo n.º 25
0
        public JsonNetResult GetInvoiceHistory_ByDateRange_Last(int itemLimit, string accountId, string endingBefore, string startDate, string endDate)
        {
            var            user     = AuthenticationCookieManager.GetAuthenticationCookie();
            List <Invoice> invoices = null;

            #region (Plan A) Get data from Redis Cache

            /*
             * try
             * {
             *  IDatabase cache = CoreServiceSettings.RedisConnectionMultiplexers.AccountManager_Multiplexer.GetDatabase();
             *
             *  string hashKey = "accountbyid:" + accountId.ToString().Replace("-", "");
             *  string hashField = "creditcard";
             *
             *  var redisValue = cache.HashGet(hashKey, hashField);
             *
             *  if (redisValue.HasValue)
             *  {
             *      accountCreditCardInfo = JsonConvert.DeserializeObject<AccountCreditCardInfo>(redisValue);
             *  }
             * }
             * catch (Exception e)
             * {
             *  var error = e.Message;
             *  //TODO: Log: error message for Redis call
             * }*/

            #endregion

            if (invoices == null)
            {
                #region (Plan B) Get data from WCF

                var accountBillingServiceClient = new AccountBillingService.AccountBillingServiceClient();

                try
                {
                    accountBillingServiceClient.Open();
                    invoices = accountBillingServiceClient.GetInvoiceHistory_ByDateRange_Last(
                        itemLimit,
                        endingBefore,
                        Convert.ToDateTime(startDate).ToUniversalTime(),          //<-- We must convert to UTC to get accurrate results
                        Convert.ToDateTime(endDate).ToUniversalTime().AddDays(1), //<-- We must convert to UTC to get accurrate results (We add 1 day to end dates to also get resuts from this day and not just up to midnight the night before)
                        accountId, Common.SharedClientKey
                        ).ToList();                                               //,
                    //user.Id,
                    //PlatformAdminSite.AccountManagementService.RequesterType.PlatformUser).ToList();

                    //Close the connection
                    WCFManager.CloseConnection(accountBillingServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(accountBillingServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = invoices;

            return(jsonNetResult);
        }
Ejemplo n.º 26
0
        public JsonNetResult GetCurrentUser()
        {
            //This is used often by the UI to refresh the user, wrap in a Try/Catch in case of intermitent failures:

            try
            {
                var userId = AuthenticationCookieManager.GetAuthenticationCookie().Id;

                if (userId == null)
                {
                    Response.Redirect("/Login");
                }

                AccountUser user = null;

                #region (Plan A) Get data from Redis Cache

                try
                {
                    //First we attempt to get the user from the Redis Cache

                    IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

                    string hashKey   = "user:"******"-", "");
                    string hashField = "model";

                    var redisValue = cache.HashGet(hashKey, hashField);

                    //con.Close();

                    if (redisValue.HasValue)
                    {
                        user = JsonConvert.DeserializeObject <AccountUser>(redisValue);
                    }
                }
                catch (Exception e)
                {
                    var error = e.Message;
                }

                #endregion

                if (user == null)
                {
                    #region (Plan B) Get data from WCF

                    //If a failure occurs, or the redis cache is empty we get the user from the WCF service
                    var accountManagementServiceClient = new AccountManagementService.AccountManagementServiceClient();

                    try
                    {
                        accountManagementServiceClient.Open();
                        user = accountManagementServiceClient.GetAccountUser(userId, Common.SharedClientKey);

                        //Close the connection
                        WCFManager.CloseConnection(accountManagementServiceClient);
                    }
                    catch (Exception e)
                    {
                        #region Manage Exception

                        string exceptionMessage = e.Message.ToString();

                        var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                        string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                        // Abort the connection & manage the exception
                        WCFManager.CloseConnection(accountManagementServiceClient, exceptionMessage, currentMethodString);

                        #endregion
                    }

                    #endregion
                }

                //Update the local cookies:
                AuthenticationCookieManager.SaveAuthenticationCookie(user);

                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResult.Data = user;

                return(jsonNetResult);
            }
            catch
            {
                // Use cookies instead
                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
                jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                var accountUser = AuthenticationCookieManager.GetAuthenticationCookie();
                jsonNetResult.Data = accountUser;

                return(jsonNetResult);
            }
        }
        public JsonNetResult AddSalesAlertEmail(string email)
        {
            var accountNameKey = AuthenticationCookieManager.GetAuthenticationCookie().AccountNameKey;

            #region Make sure account plan allow for sales leads

            var account = Common.GetAccountObject(accountNameKey);

            if (account.PaymentPlan.AllowSalesLeads == false)
            {
                JsonNetResult jsonNetResultRestricted = new JsonNetResult();
                jsonNetResultRestricted.Formatting = Formatting.Indented;
                jsonNetResultRestricted.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResultRestricted.Data = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Account plan does not allow for sales leads"
                };

                return(jsonNetResultRestricted);
            }

            #endregion

            var accountSettings = AccountSettings.GetAccountSettings_Internal(accountNameKey);

            if (!email.Contains('@') || !email.Contains('.'))
            {
                JsonNetResult jsonNetResultError = new JsonNetResult();
                jsonNetResultError.Formatting = Formatting.Indented;
                jsonNetResultError.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResultError.Data = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Please use a valid email address"
                };

                return(jsonNetResultError);
            }

            //Make updates:
            if (accountSettings.SalesSettings.AlertEmails == null)
            {
                accountSettings.SalesSettings.AlertEmails = new List <string>();
            }

            if (accountSettings.SalesSettings.AlertEmails.Count >= 15)
            {
                JsonNetResult jsonNetResultError2 = new JsonNetResult();
                jsonNetResultError2.Formatting = Formatting.Indented;
                jsonNetResultError2.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                jsonNetResultError2.Data = new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "You've reached the limit of 15 alert emails"
                };

                return(jsonNetResultError2);
            }

            foreach (string emailTest in accountSettings.SalesSettings.AlertEmails)
            {
                if (emailTest == email)
                {
                    JsonNetResult jsonNetResultError3 = new JsonNetResult();
                    jsonNetResultError3.Formatting = Formatting.Indented;
                    jsonNetResultError3.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
                    jsonNetResultError3.Data = new DataAccessResponseType {
                        isSuccess = false, ErrorMessage = "This email is already on the alert list"
                    };

                    return(jsonNetResultError3);
                }
            }


            accountSettings.SalesSettings.AlertEmails.Add(email);

            var response = AccountSettings.UpdateAccountSettings_Internal(accountNameKey, accountSettings);

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }
Ejemplo n.º 28
0
        public ActionResult Index(Login login, string returnUrl)
        {
            //RememberMe default is true
            login.RememberMe = true;

            //Sign user out (if signed in as another user)
            HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie);

            if (ModelState.IsValid)
            {
                var authResponse = new AuthenticationResponse {
                    isSuccess = false
                };

                //Attempt to log in
                var accountAuthenticationServiceClient = new AccountAuthenticationService.AccountAuthenticationServiceClient();

                try
                {
                    //Get the ip address and call origin
                    var ipAddress = Request.UserHostAddress;
                    var origin    = "Web";

                    accountAuthenticationServiceClient.Open();
                    authResponse = accountAuthenticationServiceClient.Authenticate(login.AccountName, login.Email, login.Password, ipAddress, origin, Common.SharedClientKey);

                    //Close the connection
                    WCFManager.CloseConnection(accountAuthenticationServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(accountAuthenticationServiceClient, exceptionMessage, currentMethodString);

                    // Upate the response object
                    authResponse.isSuccess    = false;
                    authResponse.ErrorMessage = WCFManager.UserFriendlyExceptionMessage;
                    //auth//response.ErrorMessages[0] = exceptionMessage;

                    #endregion
                }


                //ClaimsIdentity[] claimsIdentity = new ClaimsIdentity[0];
                //claimsIdentity[0] = authResponse.ClaimsIdentity;

                if (authResponse.isSuccess)
                {
                    // Sign User In
                    var currentUtc = new SystemClock().UtcNow;
                    HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties()
                    {
                        IsPersistent = login.RememberMe,
                        ExpiresUtc   = currentUtc.Add(TimeSpan.FromHours(6))
                    },
                                                                       authResponse.ClaimsIdentity);

                    //Store the PlatformUser object as a cookie:
                    AuthenticationCookieManager.SaveAuthenticationCookie(authResponse.AccountUser);

                    //-------------------- Uknown Accounts (Removed)-------

                    /*
                     * string subdomain = Common.GetSubDomain(Request.Url);
                     * if (subdomain.ToLower() == "accounts" || subdomain.ToLower() == "account")
                     * {
                     *  //This is the generic login route....
                     *  //Since the user had to provide the account name, redirect to the new URL
                     *  return Redirect("https://" + authResponse.AccountUser.AccountNameKey + "." + CoreServices.PlatformSettings.Urls.AccountManagementDomain + "/inventory");
                     * }
                     * else */

                    if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                    {
                        //After user is authenticated, send them to the page they were attempting to use,
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        //otherwise, send them to home:
                        return(RedirectToAction("Index", "Inventory"));
                    }
                }
                else
                {
                    //ModelState.AddModelError("", "Invalid username or password.");

                    //foreach (string error in authResponse.ErrorMessages)
                    //{
                    ModelState.AddModelError("CoreServiceError", authResponse.ErrorMessage);
                    //}


                    //Removed

                    /*
                     * string subdomain = Common.GetSubDomain(Request.Url);
                     * if (subdomain.ToLower() == "accounts" || subdomain.ToLower() == "account")
                     * {
                     *  //This is the generic login route, so we remove the account name and force the user to add it.
                     *  login.AccountName = null;
                     * }*/

                    return(View(login));
                }
            }
            else
            {
                return(View(login));
            }
        }
Ejemplo n.º 29
0
 public ActionResult LogOut()
 {
     HttpContext.GetOwinContext().Authentication.SignOut();
     AuthenticationCookieManager.DestoryAuthenticationCookie();
     return(View());
 }
Ejemplo n.º 30
0
        public static List <ImageRecordGroupModel> GetImageRecordsForObject(string accountNameKey, string storagePartitionName, string imageFormatGroupTypeNameKey, string objectId, bool listingsOnly = false)
        {
            var imageRecords = new List <ImageRecordGroupModel>();

            var accountId = AuthenticationCookieManager.GetAuthenticationCookie().AccountID.ToString();

            #region Get Image Formats/FormatGroups for this ImageFormatGroupTypeNameKey (Local cache first ---> Then Redis --> Then WCF/SQL)

            List <ImageFormatGroupModel> imageFormats = null;

            #region (Plan A) Get ImageFormats for this ImageFormatGroupType from Local Cache

            bool   localCacheEmpty = false;
            string localCacheKey   = accountNameKey + ":imageFormats:" + imageFormatGroupTypeNameKey;

            try
            {
                imageFormats = (List <ImageFormatGroupModel>)HttpRuntime.Cache[localCacheKey];
            }
            catch (Exception e)
            {
                var error = e.Message;
                //TODO: Log: error message for local cache call
            }

            #endregion

            if (imageFormats == null)
            {
                localCacheEmpty = true;

                #region (Plan B) Get ImageFormats from ImageFormatsManager Shared Method (Redis or WCF call)

                imageFormats = SettingsCommon.GetImageFormatsHelper(accountNameKey, imageFormatGroupTypeNameKey);

                #endregion
            }


            if (localCacheEmpty)
            {
                #region store Account into local cache

                //store formats in local cache for 60 seconds:
                HttpRuntime.Cache.Insert(localCacheKey, imageFormats, null, DateTime.Now.AddSeconds(20), TimeSpan.Zero);

                #endregion
            }

            #endregion

            #region Get all image records for this object

            #region Connect to Table Storage & Set Retry Policy (Legacy)

            /*
             * CloudStorageAccount storageAccount;
             *
             * // Credentials are from centralized CoreServiceSettings
             * StorageCredentials storageCredentials = new StorageCredentials(CoreServices.PlatformSettings.Storage.AccountName, CoreServices.PlatformSettings.Storage.AccountKey);
             * storageAccount = new CloudStorageAccount(storageCredentials, false);
             * storageAccount = new CloudStorageAccount(storageCredentials, false);
             * CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
             *
             * //Create and set retry policy
             * //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4);
             * IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 4);
             * cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy;
             */
            #endregion

            #region Connect to table storage partition & Set Retry Policy

            #region Get Storage Partition

            if (CoreServices.PlatformSettings.StorageParitions == null || CoreServices.PlatformSettings.StorageParitions.ToList().Count == 0)
            {
                //No Storage Partitions Available in Static List, refresh list from Core Services
                Common.RefreshPlatformSettings();
            }

            //Get the storage partition for this account
            var storagePartition = CoreServices.PlatformSettings.StorageParitions.FirstOrDefault(partition => partition.Name == storagePartitionName);

            if (storagePartition == null)
            {
                //May be a new partition, refresh platform setting and try again
                Common.RefreshPlatformSettings();
                storagePartition = CoreServices.PlatformSettings.StorageParitions.FirstOrDefault(partition => partition.Name == storagePartitionName);
            }

            #endregion

            var cdnEndpoint = "https://" + storagePartition.CDN + "/";

            CloudStorageAccount storageAccount;
            StorageCredentials  storageCredentials = new StorageCredentials(storagePartition.Name, storagePartition.Key);
            storageAccount = new CloudStorageAccount(storageCredentials, false);
            CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();

            //Create and set retry policy for logging
            //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4);
            IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 4);
            cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy;


            #endregion

            CloudTable cloudTable = null;

            if (!listingsOnly)
            {
                cloudTable = cloudTableClient.GetTableReference("acc" + accountId.Replace("-", "").ToLower() + imageFormatGroupTypeNameKey + "imgs");
            }
            else
            {
                cloudTable = cloudTableClient.GetTableReference("acc" + accountId.Replace("-", "").ToLower() + imageFormatGroupTypeNameKey + "lstimgs");
            }

            List <ImageRecordTableEntity> imageRecordEntities;

            //var imageRecordEntities = Internal.ImageRecordTableStorage.RetrieveImageRecords(accountId, imageFormatGroupTypeNameKey, objectId, listingsOnly);
            try
            {
                imageRecordEntities = (from record in cloudTable.CreateQuery <ImageRecordTableEntity>().Where(p => p.PartitionKey == objectId) select record).ToList(); //new TableQuery<ImageRecordTableEntity>().AsQueryable().Where(p => p.PartitionKey == objectId).ToList();
            }
            catch
            {
                //Table may not exist yet, return empty record set (We do not use CreateIfNotExists on TableClient in case imageFormatGroupTypeNameKey is not valid!!!!)
                imageRecordEntities = new List <ImageRecordTableEntity>();
            }

            #endregion

            #region  Convert FormatGroups/Formats to RecordGroups/Records And merge them with Records (Where records exist)

            foreach (ImageFormatGroupModel imageFormatGroup in imageFormats)
            {
                var imageRecordGroupModel = new ImageRecordGroupModel
                {
                    GroupName    = imageFormatGroup.ImageFormatGroupName,
                    GroupNameKey = imageFormatGroup.ImageFormatGroupNameKey
                };

                imageRecordGroupModel.ImageRecords = new List <ImageRecordModel>();

                foreach (ImageFormatModel imageFormat in imageFormatGroup.ImageFormats)
                {
                    if (listingsOnly && !imageFormat.Listing)
                    {
                        //ignore
                    }
                    else
                    {
                        #region Get the associated record for each format (if one exists, or create a null object for it if a record does not

                        var recordExists = false;

                        foreach (ImageRecordTableEntity tableEntity in imageRecordEntities)
                        {
                            if (tableEntity.ImageKey == imageFormat.ImageFormatGroupNameKey + "-" + imageFormat.ImageFormatNameKey)
                            {
                                recordExists = true;

                                #region A record exists for this format, convert and remove from list

                                imageRecordGroupModel.ImageRecords.Add(Transforms.TableEntity_To_ImageRecord(cdnEndpoint, tableEntity, imageFormat, imageFormat.Gallery));

                                #endregion
                            }
                        }

                        if (!recordExists)
                        {
                            #region A record does not exist, use a null version of the format slug instead

                            imageRecordGroupModel.ImageRecords.Add(Transforms.ImageFormat_To_ImageRecord(imageFormat));

                            #endregion
                        }

                        #endregion
                    }
                }

                if (imageRecordGroupModel.ImageRecords.Count > 0)
                {
                    imageRecords.Add(imageRecordGroupModel);  //<-- Only append if group has records or format slugs
                }
            }

            #endregion

            return(imageRecords);
        }