示例#1
0
        internal static void CreateBalanceAccount(int user_id)
        {
            var config = new Dictionary <string, object>
            {
                { "bootstrap.servers", "kafka1:9093,kafka2:9093" }
            };

            using (var producer = new Producer <Null, string>(config, null, new StringSerializer(Encoding.UTF8)))
            {
                using (var data = new DataContext())
                {
                    data.Database.EnsureCreated();

                    var acc = new Models.AccountViewModel
                    {
                        ID     = System.Guid.NewGuid().ToString(),
                        UserID = user_id,
                        Host   = System.Environment.GetEnvironmentVariable("HOSTNAME") ?? "localhost",
                    };

                    data.Accounts.Add(acc);
                    data.SaveChanges();

                    var dr = producer.ProduceAsync("balance-events", null, $"{{ type: \"ACC_CREATED\"," +
                                                   $" data: {{ \"user\" : {acc.UserID}, \"acc_id\": \"{acc.ID}\" }}}}").Result;
                    Console.WriteLine($"Delivered '{dr.Value}' to: {dr.TopicPartitionOffset}");
                }
            }
        }
        public ActionResult CreateAccount(Models.AccountViewModel acct)
        {
            var acctService = new AccountServiceClient();

            var profile = new Account();

            profile.FirstName = acct.FirstName;
            profile.LastName  = acct.LastName;
            profile.UserName  = acct.UserName;
            profile.Password  = acct.Password;

            var message = acctService.CreateAccount(profile);

            return(Json(message, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        // GET: Bank
        public ActionResult Index()
        {
            var account = _accountService.GetById(LoginAccount.Id);

            if (string.IsNullOrEmpty(account.Bank) || string.IsNullOrEmpty(account.BankNumber))
            {
                //没有绑定银行 提示用户绑定银行卡
                return(RedirectToAction("Add"));
            }
            else
            {
                Models.AccountViewModel viewModel = AutoMapper.Mapper.Map <Models.AccountViewModel>(account);
                return(View(viewModel));
            }
        }
        public async Task <IActionResult> Index()
        {
            HomeViewModel viewModel = new HomeViewModel();

            Nethereum.Web3.Web3 web3 = new Nethereum.Web3.Web3("http://192.168.0.103:8545");
            var accounts             = await web3.Personal.ListAccounts.SendRequestAsync();

            foreach (var account in accounts)
            {
                Models.AccountViewModel accountViewModel = new Models.AccountViewModel()
                {
                    Account = account
                };
                viewModel.Accounts.Add(accountViewModel);
            }

            return(View(viewModel));
        }
        public IHttpActionResult InitAccount(Models.AccountViewModel dtoItem)
        {
            Library.DTO.Notification notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            // authentication
            Module.Framework.BLL fwBll = new Module.Framework.BLL();
            if (!fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanCreate))
            {
                // create new case
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Properties.Resources.NOT_AUTHORIZED;
                return(Ok(new Library.DTO.ReturnData <DTO.UserMng.UserProfile>()
                {
                    Data = null, Message = notification
                }));
            }

            // validation
            if (!Helper.CommonHelper.ValidateDTO <Models.AccountViewModel>(dtoItem, out notification))
            {
                return(Ok(new Library.DTO.ReturnData <Models.AccountViewModel>()
                {
                    Data = dtoItem, Message = notification
                }));
            }

            // create asp.net users
            string aspNetUsersId = string.Empty;

            try
            {
                using (AuthRepository _repo = new AuthRepository())
                {
                    if (dtoItem.Password.Length >= 7)
                    {
                        if (_repo.CheckUsernameOrEmailExists(dtoItem.UserName, dtoItem.Email))
                        {
                            throw new Exception("Username or email address already used by other user!");
                        }

                        aspNetUsersId = _repo.CreateUser(dtoItem.UserName, dtoItem.Password, dtoItem.Email);
                    }
                    else
                    {
                        throw new Exception("Password length must be at least 7 chars");
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(Ok(new Library.DTO.ReturnData <DTO.UserMng.UserProfile>()
                {
                    Data = null, Message = notification
                }));
            }

            // continue processing
            Hashtable input = new Hashtable();

            input["AspNetUserId"] = aspNetUsersId;
            input["EmployeeID"]   = dtoItem.EmployeeID;
            input["IsActive"]     = dtoItem.IsActive;
            input["UserGroupID"]  = dtoItem.UserGroupID;
            int newID = (int)executor.CustomFunction(ControllerContext.GetAuthUserId(), "initaccount", input, out notification);

            return(Ok(new Library.DTO.ReturnData <int>()
            {
                Data = newID, Message = notification
            }));
        }