Beispiel #1
0
        public static ResultsPair <LocalCoins.Portfolio> UpdatePortfolio(int portfolioId, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    Portfolios portfolio = db.Portfolios.FirstOrDefault(x => x.PortfolioId == portfolioId);
                    if (portfolio != null)
                    {
                        portfolio.Name        = portfolioName.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });
                        portfolio.DisplayType = (short)displayType;
                        portfolio.IsDefault   = isDefault;

                        db.Update(portfolio);
                        db.SaveChanges();
                    }

                    return(ResultsPair.Create(ResultsItem.Success("Successfully updated portfolio name."), portfolio.Adapt <LocalCoins.Portfolio>()));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "UpdatePortfolio", $"portfolioId:{portfolioId},portfolioName:{portfolioName}" }, ex);
                return(ResultsPair.CreateError <LocalCoins.Portfolio>($"Unable to update portfolio. {ex.Message}"));
            }
        }
Beispiel #2
0
        public static async Task <ResultsPair <LocalCoins.Portfolio> > InsertNewPortfolio(int userId, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    Portfolios portfolio = new Portfolios
                    {
                        UserId      = userId,
                        Name        = portfolioName.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM }),
                        DisplayType = (short)displayType,
                        IsDefault   = isDefault
                    };

                    db.Portfolios.Add(portfolio);
                    await db.SaveChangesAsync();

                    return(ResultsPair.Create(ResultsItem.Success("Successfully created a new portfolio."), portfolio.Adapt <LocalCoins.Portfolio>()));
                }
            }
            catch (Exception ex)
            {
                return(ResultsPair.CreateError <LocalCoins.Portfolio>($"Unable to create a new portfolio. {ex.Message}"));
            }
        }
Beispiel #3
0
        private static async Task <ResultsPair <LocalAccount.PTUserInfo> > CreateNewPTUserInfo(LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    PTUserInfo ptUserInfo = new PTUserInfo
                    {
                        UserId                 = user.UserId,
                        SubscriptionLevel      = (byte)SubscriptionLevel.Free,
                        SubscriptionExpireDate = null
                    };

                    db.PTUserInfo.Add(ptUserInfo);
                    await db.SaveChangesAsync();

                    LocalAccount.PTUserInfo localSubscription = ptUserInfo.Adapt <LocalAccount.PTUserInfo>();

                    return(ResultsPair.Create(ResultsItem.Success("Successfully created a new subscription."), localSubscription));
                }
            }
            catch (Exception ex)
            {
                return(ResultsPair.CreateError <LocalAccount.PTUserInfo>($"Unable to create a new PTUserInfo: {ex.Message}"));
            }
        }
Beispiel #4
0
        // Creates a new user and then redirects them to the login page.
        public static async Task <ResultsPair <LocalAccount.PegaUser> > CreateNewUser(LocalAccount.PegaUser user)
        {
            using (HttpClient client = new HttpClient())
            {
                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Username", user.Username),
                    new KeyValuePair <string, string>("Password", user.Password),
                    new KeyValuePair <string, string>("Email", user.Email),
                    new KeyValuePair <string, string>("EmailSubscribePreferenceCode", ((int)EmailPreferences.Default).ToString()),
                    new KeyValuePair <string, string>("platform", ((int)Platform.PegaTrade).ToString())
                });

                HttpResponseMessage response = await client.PostAsync($"{baseUrl}/v1/Account/Create", content);

                if (response.IsSuccessStatusCode)
                {
                    string jsonString = await response.Content.ReadAsStringAsync();

                    ResultsItem createUserResult = NetJSON.NetJSON.Deserialize <PegasunAPIResult>(jsonString).ConvertToResultsItem();
                    if (createUserResult.ResultType == ResultsType.Successful)
                    {
                        var getUserResult = await AuthorizeUser(user.Username, user.Password);

                        if (!getUserResult.Result.IsSuccess)
                        {
                            return(getUserResult);
                        }

                        return(ResultsPair.Create(createUserResult, getUserResult.Value));
                    }

                    return(ResultsPair.CreateError <LocalAccount.PegaUser>(createUserResult.Message));
                }
            }

            return(ResultsPair.CreateError <LocalAccount.PegaUser>(Lang.ServerConnectionError));
        }