public async Task <IActionResult> Post([FromBody] RegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AppUser userIdentity = AccountsHelper.ConvertToDbObj(model);

            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }

            // Create ContacDetails if provided
            await this.contactDetailsService.Insert(model, userIdentity.Id);

            if (model.Address != null)
            {
                await this.addressesService.Insert(model.Address, userIdentity.Id);
            }

            // await _appDbContext.Customers.AddAsync(new Customer { IdentityId = userIdentity.Id, Location = model.Location });
            // await _appDbContext.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }
Example #2
0
        public virtual JsonResult DynamicGridData(int page, int rows, String search, String sidx, String sord)
        {
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = rows;
            IQueryable <UserGroup> searchQuery = userGroupService.GetSearchQuery(search);
            int totalRecords = userGroupService.GetCount(searchQuery);
            var totalPages   = (int)Math.Ceiling((float)totalRecords / pageSize);
            var userGroups   = searchQuery.OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize).ToList();
            var jsonData     = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows    = (
                    from userGroup in userGroups
                    select new
                {
                    id = userGroup.Id,
                    cell = new[] { HttpUtility.HtmlEncode(userGroup.Name),
                                   String.Format("{0}<a style=\"margin-left:7px\" href=\"{1}\">{2}</a>",
                                                 AccountsHelper.GetUserGroupRoles(userGroup),
                                                 Url.Action(MVC.Admin.UserGroup.Roles(userGroup.Id)),
                                                 Translate(".Model.UserGroup.Roles")),
                                   String.Format(JqGridConstants.UrlTemplate,
                                                 Url.Action(MVC.Admin.UserGroup.Users(userGroup.Id)),
                                                 Translate(".Model.UserGroup.Users")), String.Format("<a href=\"{0}\"><em class=\"delete\" style=\"margin-left: 10px;\"/></a>",
                                                                                                     Url.Action(MVC.Admin.UserGroup.Remove(userGroup.Id))) }
                }).ToArray()
            };

            return(Json(jsonData));
        }
        /// <summary>
        /// Recursively tries to get a movements page from the MP API.
        /// </summary>
        public static SearchPage <Movement> GetMovementsPage(Int32 offset, Int32 limit, OAuthResponse authorization, DateTime dateFrom, DateTime dateTo, int retryNumber = 0)
        {
            AccountsHelper ah = new AccountsHelper();

            // Set access token
            ah.AccessToken = GetAccessToken(authorization);

            // Prepare API call arguments
            List <KeyValuePair <string, string> > args = new List <KeyValuePair <string, string> >();

            if (authorization.IsAdmin)
            {
                args.Add(new KeyValuePair <string, string>("user_id", authorization.UserId.ToString()));
            }
            // Try optimize the query by site id, taking advantage of the search sharding
            if (authorization.SiteId != null)
            {
                args.Add(new KeyValuePair <string, string>("site_id", authorization.SiteId));
            }
            args.Add(new KeyValuePair <string, string>("sort", "date_created"));
            args.Add(new KeyValuePair <string, string>("criteria", "desc"));
            args.Add(new KeyValuePair <string, string>("offset", offset.ToString()));
            args.Add(new KeyValuePair <string, string>("limit", limit.ToString()));
            args.Add(new KeyValuePair <string, string>("range", "date_created"));
            args.Add(new KeyValuePair <string, string>("begin_date", HttpUtility.UrlEncode(dateFrom.GetDateTimeFormats('s')[0].ToString() + ".000Z")));
            args.Add(new KeyValuePair <string, string>("end_date", HttpUtility.UrlEncode(dateTo.GetDateTimeFormats('s')[0].ToString() + ".000Z")));

            // Call API
            SearchPage <Movement> searchPage = null;

            try
            {
                searchPage = ah.SearchMovements(args);
            }
            catch (RESTAPIException raex)
            {
                // Retries the same call until max is reached
                if (retryNumber <= MAX_RETRIES)
                {
                    LogHelper.WriteLine("SearchMovements breaks. Retry num: " + retryNumber.ToString());
                    BackendHelper.GetMovementsPage(offset, limit, authorization, dateFrom, dateTo, retryNumber + 1);
                }
                else
                {
                    // then breaks
                    throw raex;
                }
            }

            if (searchPage != null)
            {
                return(searchPage);
            }
            else
            {
                LogHelper.WriteLine("null");
                return(null);
            }
        }
 public PayoutJsonHelper(bool ok, LimitActiveHelper autoSwitch, LimitActiveHelper holdup, PrimaryHelper primary, string method, AccountsHelper accounts)
 {
     this.ok         = ok;
     this.autoSwitch = autoSwitch;
     this.holdup     = holdup;
     this.primary    = primary;
     this.method     = method;
     this.accounts   = accounts;
 }
Example #5
0
        private async void SetUpAccounts()
        {
            accountList = await AccountsHelper.LoadAccountList();

            accountListView.ItemsSource = accountList;

            if (accountList.Count == 0)
            {
                ((App)(Application.Current)).NavigationService.Navigate(typeof(SignInView));
            }
        }
        /// <summary>
        /// Load search grid with API values.
        /// </summary>
        private void LoadSearchGrid(int offset, int pageSize)
        {
            AccountsHelper ah = new AccountsHelper();

            try
            {
                this.Cursor = Cursors.WaitCursor;

                // Set access token and hook API call event
                ah.AccessToken = _authorization.AccessToken;
                ah.APICall    += new APICallEventHandler(OnAPICall);

                // Prepare API call arguments
                List <KeyValuePair <string, string> > args = new List <KeyValuePair <string, string> >();
                args.Add(new KeyValuePair <string, string>("sort", "date_created"));
                args.Add(new KeyValuePair <string, string>("criteria", "desc"));
                args.Add(new KeyValuePair <string, string>("offset", (offset - 1).ToString()));
                args.Add(new KeyValuePair <string, string>("limit", pageSize.ToString()));

                // Call API
                DateTime dt = DateTime.Now;
                SearchPage <Movement> searchPage = ah.SearchMovements(args);
                TimeSpan pt = DateTime.Now.Subtract(dt);
                responseTime.Text = pt.TotalMilliseconds.ToString();
                List <Movement> movements = searchPage.Results;

                // Bind this info to the grid view
                MovementsGridView.AutoGenerateColumns = false;
                MovementsGridView.DataSource          = movements;

                // Set pager info
                pagerFrom.Text  = offset.ToString();
                pagerTo.Text    = (offset + movements.Count - 1).ToString();
                pagerTotal.Text = searchPage.Total.ToString();

                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("Search Movements failure: " + ex.Message);
            }
            finally
            {
                ah.APICall -= new APICallEventHandler(OnAPICall);
            }
        }
Example #7
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var navigation = new NavItem <NavUrl>();

            navigation.AddGroup("Content")
            .AddItem("Block", new NavUrl("Index", "ContentMgmt", "ControlPanel", ContentType.Block.S()))
            .AddItem("Blog", new NavUrl("Index", "ContentMgmt", "ControlPanel", ContentType.Blog.S()))
            .AddItem("Page", new NavUrl("Index", "ContentMgmt", "ControlPanel", ContentType.Page.S()));

            navigation.AddGroup("Users")
            .AddItem("Users", new NavUrl("Index", "Users", "ControlPanel"));

            //ViewBag.SideNav = navigation;

            ViewBag.IsAdmin = AccountsHelper.IsAdmin(filterContext.HttpContext.User.Identity.Name);

            base.OnActionExecuted(filterContext);
        }
        /// <summary>
        /// Do get summary.
        /// </summary>
        private void getSummaryButton_Click(object sender, EventArgs e)
        {
            AccountsHelper ah = new AccountsHelper();

            try
            {
                this.Cursor = Cursors.WaitCursor;

                // Set access token and hook API call event
                ah.AccessToken = _authorization.AccessToken;
                ah.APICall    += new APICallEventHandler(OnAPICall);

                // Call API
                DateTime       dt = DateTime.Now;
                AccountBalance ab = ah.GetAccountBalance(_authorization.UserId);
                TimeSpan       pt = DateTime.Now.Subtract(dt);
                responseTime.Text = pt.TotalMilliseconds.ToString();

                // Set currency id
                CurrencyIdLabel.Text = ab.CurrencyId;

                // Set available balance
                AvailableBalanceLabel.Text          = ab.AvailableBalance.ToString();
                AvailableBalanceGridView.DataSource = ab.AvailableBalanceByTransactionType.ToList();

                // Set unavailable balance
                UnavailableBalanceLabel.Text          = ab.UnavailableBalance.ToString();
                UnavailableBalanceGridView.DataSource = ab.UnavailableBalanceByReason.ToList();

                // Set total balance
                TotalBalanceLabel.Text = ab.TotalBalance.ToString();

                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("Get Summary failure: " + ex.Message);
            }
            finally
            {
                ah.APICall -= new APICallEventHandler(OnAPICall);
            }
        }
Example #9
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ViewBag.Version = WebConfigurationManager.AppSettings["AppVersion"];
            ViewBag.IsAdmin = AccountsHelper.IsAdmin(filterContext.HttpContext.User.Identity.Name);

            var mainMenu = new Dictionary <string, NavItem <string> >();

            foreach (var cat in _ctx.DContentCategories)
            {
                var navGroup = new NavItem <string>();
                navGroup.Title = cat.Title;
                navGroup.Url   = cat.Route;
                foreach (var routeItem in _ctx.VRouteItems.Where(ri => ri.CategoryId == cat.Id).OrderBy(ri => ri.Position))
                {
                    navGroup.AddItem(routeItem.RouteTitle, routeItem.Route);
                }
                mainMenu[cat.Name] = navGroup;
            }

            ViewBag.MainMenu = mainMenu;

            _ctx.UpdateLastOnline(filterContext.HttpContext.User.Identity.Name, DateTime.UtcNow);
            base.OnActionExecuted(filterContext);
        }
Example #10
0
        private void btnLoadAccounts_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Multiselect      = true;
                ofd.CheckFileExists  = true;
                ofd.RestoreDirectory = true;
                ofd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
                ofd.Filter           = @"Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
                ofd.Title            = @"Load accounts lists";

                // NOTE: User didn't select any files
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // NOTE: This will clear all previously loaded accounts and load new ones
                _accounts.Clear();
                _accounts = AccountsHelper.ValidateAndLoadAccounts(ofd.FileNames);

                lblAccounts.Text = $@"{lblAccounts.Tag} ({_accounts.Count})";
            }
        }
 public AccountController(AccountsHelper accountsHelper)
 {
     //UserManager = userManager;
     //SignInManager = signInManager;
     _accountsHelper = accountsHelper;
 }
Example #12
0
 private void CleanUpUserList()
 {
     AccountsHelper.SaveAccountList(UserSelect.accountList);
 }
Example #13
0
        /// <summary>
        /// Load search grid with API values.
        /// </summary>
        private void LoadSearchGrid(int offset, int pageSize)
        {
            AccountsHelper ah = new AccountsHelper();

            try
            {
                this.Cursor = Cursors.WaitCursor;

                // Set access token and hook API call event
                ah.AccessToken = _authorization.AccessToken;
                ah.APICall += new APICallEventHandler(OnAPICall);

                // Prepare API call arguments
                List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>();
                args.Add(new KeyValuePair<string, string>("sort", "date_created"));
                args.Add(new KeyValuePair<string, string>("criteria", "desc"));
                args.Add(new KeyValuePair<string, string>("offset", (offset - 1).ToString()));
                args.Add(new KeyValuePair<string, string>("limit", pageSize.ToString()));

                // Call API
                DateTime dt = DateTime.Now;
                SearchPage<Movement> searchPage = ah.SearchMovements(args);
                TimeSpan pt = DateTime.Now.Subtract(dt);
                responseTime.Text = pt.TotalMilliseconds.ToString();
                List<Movement> movements = searchPage.Results;

                // Bind this info to the grid view
                MovementsGridView.AutoGenerateColumns = false;
                MovementsGridView.DataSource = movements;

                // Set pager info
                pagerFrom.Text = offset.ToString();
                pagerTo.Text = (offset + movements.Count - 1).ToString();
                pagerTotal.Text = searchPage.Total.ToString();

                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("Search Movements failure: " + ex.Message);
            }
            finally
            {
                ah.APICall -= new APICallEventHandler(OnAPICall);
            }
        }
Example #14
0
        /// <summary>
        /// Do get summary.
        /// </summary>
        private void getSummaryButton_Click(object sender, EventArgs e)
        {
            AccountsHelper ah = new AccountsHelper();

            try
            {
                this.Cursor = Cursors.WaitCursor;

                // Set access token and hook API call event
                ah.AccessToken = _authorization.AccessToken;
                ah.APICall += new APICallEventHandler(OnAPICall);

                // Call API
                DateTime dt = DateTime.Now;
                AccountBalance ab = ah.GetAccountBalance(_authorization.UserId);
                TimeSpan pt = DateTime.Now.Subtract(dt);
                responseTime.Text = pt.TotalMilliseconds.ToString();

                // Set currency id
                CurrencyIdLabel.Text = ab.CurrencyId;

                // Set available balance
                AvailableBalanceLabel.Text = ab.AvailableBalance.ToString();
                AvailableBalanceGridView.DataSource = ab.AvailableBalanceByTransactionType.ToList();

                // Set unavailable balance
                UnavailableBalanceLabel.Text = ab.UnavailableBalance.ToString();
                UnavailableBalanceGridView.DataSource = ab.UnavailableBalanceByReason.ToList();

                // Set total balance
                TotalBalanceLabel.Text = ab.TotalBalance.ToString();

                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("Get Summary failure: " + ex.Message);
            }
            finally
            {
                ah.APICall -= new APICallEventHandler(OnAPICall);
            }
        }