示例#1
0
        public IHttpActionResult Put(int id, [FromBody] DtoUserInfo dtoUser)
        {
            var updatetUser = db.Users.Find(id);

            if (updatetUser == null || updatetUser.UserId != dtoUser.UserId)
            {
                return(Content(HttpStatusCode.NotFound, "Vi kan ikke finne denne brukeren"));
            }
            if (!String.IsNullOrEmpty(dtoUser.name))
            {
                updatetUser.name = dtoUser.name;
            }
            if (!String.IsNullOrEmpty(dtoUser.email))
            {
                updatetUser.email = dtoUser.email;
            }
            if (!String.IsNullOrEmpty(dtoUser.password))
            {
                updatetUser.password = dtoUser.password;
            }



            db.Entry(updatetUser).State = EntityState.Modified;
            db.SaveChanges();

            //var UpdatedUser =DtoHelper.
            dtoUser.isAdmin = updatetUser.isAdmin;
            return(Ok(dtoUser));
        }
示例#2
0
        public static decimal GetBalance(DtoUserInfo userInfo, Currency currency)
        {
            switch (currency)
            {
            // Most used pairs
            case Currency.btc: return(userInfo.Funds.Btc);

            case Currency.ltc: return(userInfo.Funds.Ltc);

            case Currency.nvc: return(userInfo.Funds.Nmc);

            case Currency.eur: return(userInfo.Funds.Eur);

            case Currency.usd: return(userInfo.Funds.Usd);

            case Currency.gbp: return(userInfo.Funds.Gbp);

            case Currency.cnh: return(userInfo.Funds.Cnh);

            // Exotic pairs
            case Currency.rur: return(userInfo.Funds.Rur);

            case Currency.nmc: return(userInfo.Funds.Nmc);

            case Currency.trc: return(userInfo.Funds.Trc);

            case Currency.ppc: return(userInfo.Funds.Ppc);

            case Currency.ftc: return(userInfo.Funds.Ftc);

            case Currency.xpm: return(userInfo.Funds.Xpm);

            default: throw new ApplicationException("GetBalance(" + currency + ") could not be processed.");
            }
        }
示例#3
0
        private static void GetUserInfo()
        {
            DtoUserInfo info = violinBtce.GetInfo();

            Console.WriteLine(info);
            Console.ReadLine();
        }
示例#4
0
        private static bool ValidateUser(DtoUserInfo entity, out string errMsg)
        {
            errMsg = "";
            if (entity == null)
            {
                errMsg = "用户数据为空,很检查后重试";
                return(false);
            }

            if (string.IsNullOrEmpty(entity.UserUid))
            {
                errMsg += "用户标识不能为空;";
            }

            if (string.IsNullOrEmpty(entity.FullName))
            {
                errMsg += "用户姓名不能为空;";
            }

            if (string.IsNullOrEmpty(entity.UserNum))
            {
                errMsg += "用户工号不能为空;";
            }

            return(string.IsNullOrEmpty(errMsg));
        }
示例#5
0
        public void GetBalance(Currency currency)
        {
            // Arrange
            DtoUserInfo dummyUserInfo = new DtoUserInfo
            {
                Funds = new DtoFunds()
                {
                    Btc = 100,
                    Ltc = 101,
                    Nmc = 102,
                    Nvc = 103,
                    Trc = 104,
                    Ppc = 105,
                    Ftc = 106,
                    Usd = 107,
                    Rur = 108,
                    Eur = 109,
                    Xpm = 110,
                    Cnh = 111,
                    Gbp = 112
                }
            };

            // Act
            decimal result = Operations.GetBalance(dummyUserInfo, currency);

            // Assert

            switch (currency)
            {
            // Most used pairs
            case Currency.btc: Assert.AreEqual(dummyUserInfo.Funds.Btc, result); break;

            case Currency.ltc: Assert.AreEqual(dummyUserInfo.Funds.Ltc, result); break;

            case Currency.nvc: Assert.AreEqual(dummyUserInfo.Funds.Nmc, result); break;

            case Currency.eur: Assert.AreEqual(dummyUserInfo.Funds.Eur, result); break;

            case Currency.usd: Assert.AreEqual(dummyUserInfo.Funds.Usd, result); break;

            case Currency.gbp: Assert.AreEqual(dummyUserInfo.Funds.Gbp, result); break;

            case Currency.cnh: Assert.AreEqual(dummyUserInfo.Funds.Cnh, result); break;

            // Exotic pairs
            case Currency.rur: Assert.AreEqual(dummyUserInfo.Funds.Rur, result); break;

            case Currency.nmc: Assert.AreEqual(dummyUserInfo.Funds.Nmc, result); break;

            case Currency.trc: Assert.AreEqual(dummyUserInfo.Funds.Trc, result); break;

            case Currency.ppc: Assert.AreEqual(dummyUserInfo.Funds.Ppc, result); break;

            case Currency.ftc: Assert.AreEqual(dummyUserInfo.Funds.Ftc, result); break;

            case Currency.xpm: Assert.AreEqual(dummyUserInfo.Funds.Xpm, result); break;
            }
        }
示例#6
0
        /// <summary>
        /// Gets a decimal value corresponding to the balance in the specified currency
        /// </summary>
        /// <param name="currency">A Currency enumeration value</param>
        /// <exception cref="OperationCanceledException">Thrown when requesting information from server fails.</exception>
        /// <exception cref="NullUserInfoException">Thrown when API key and/or secret are undefined.</exception>
        public decimal GetBalance(Currency currency)
        {
            if (!LoggedOnOperationsAreAllowed)
            {
                throw new NullUserInfoException();
            }

            _userInfo = GetInfo();

            var balance = Operations.GetBalance(_userInfo, currency);

            return(balance);
        }
示例#7
0
        /// <summary>
        /// Gets a DtoUserInfo object of the owner of the key and secret passed on the constructor
        /// </summary>
        /// <returns>DtoUserInfo</returns>
        /// <exception cref="OperationCanceledException">Thrown when requesting information from server fails.</exception>
        /// <exception cref="NullUserInfoException">Thrown when API key and/or secret are undefined.</exception>
        public DtoUserInfo GetInfo()
        {
            if (!LoggedOnOperationsAreAllowed)
            {
                throw new NullUserInfoException();
            }

            var getInfoOperation = Operations.GetInfo();

            _userInfo = PerformOperation <DtoUserInfo>(getInfoOperation);

            return(_userInfo);
        }
示例#8
0
        public void GetInfo(string key, string secret, bool keyAndSecretAreSpecified)
        {
            // Pre requirements
            SetKeyAndSecretSpecificationRequirement(key, secret, keyAndSecretAreSpecified);

            // Arrange
            ViolinBtce violinBtce = keyAndSecretAreSpecified ? new ViolinBtce(key, secret) : new ViolinBtce();

            // Act
            DtoUserInfo result = violinBtce.GetInfo();

            // Assert
            Assert.AreEqual(0, result.OpenOrders);
        }
示例#9
0
        public async Task <IActionResult> SaveUser(int type, DtoUserInfo entity)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                string errMsg;
                bool   valid = ValidateUser(entity, out errMsg);
                if (!valid)
                {
                    msg.status  = -1;
                    msg.message = errMsg;
                    return(Json(msg));
                }
                entity.LastModifyTime     = DateTime.Now;
                entity.LastModifyUserId   = base.UserId;
                entity.LastModifyUserName = base.UserId;
                var user = await base.GetSignedUser();

                string viewRootCode = user.ViewRootCode;
                if (!string.IsNullOrEmpty(viewRootCode) && viewRootCode != rootId)
                {
                    bool admin = await this._contextService.IsInRole(base.UserId, Constans.SUPPER_ADMIN_ROLE);

                    if (admin)
                    {
                        viewRootCode = "";
                    }
                }

                int ret = await this._service.SaveUserInfo(entity, type, viewRootCode);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
示例#10
0
        public IHttpActionResult GetAllUsers(string email, string password)
        {
            var user = db.Users.SingleOrDefault(x => x.email == email && x.password == password);

            if (user == null)
            {
                return(Content(HttpStatusCode.NotFound, "Denne medlemmen finner vi ikke"));
            }
            var token   = MyTokenManager.GenerateToken(user.email);
            var dtoUser = new DtoUserInfo {
                UserId = user.UserId, name = user.name, email = user.email, password = user.password, isAdmin = user.isAdmin, token = token
            };

            return(Ok(dtoUser));
        }
示例#11
0
        public async Task <IActionResult> Edit(string userId, string pcode, string pname)
        {
            IUserInfo model;

            if (string.IsNullOrEmpty(userId))
            {
                model = new DtoUserInfo();
                if (string.IsNullOrEmpty(pcode))
                {
                    throw new ArgumentNullException("pcode", "请选择上层组织");
                }
                else
                {
                    model.OrgCode      = pcode;
                    model.OrgName      = pname;
                    model.ViewRootCode = pcode;
                    model.ViewRootName = pname;
                }
            }
            else
            {
                model = await this._service.GetUserInfo(userId);

                if (model == null)
                {
                    throw new ArgumentOutOfRangeException("userId", "不存在对应的用户");
                }
                if (string.IsNullOrEmpty(model.ViewRootCode))
                {
                    model.ViewRootCode = pcode;
                    model.ViewRootName = pname;
                }
            }

            return(View(model));
        }
示例#12
0
        public async Task <int> SaveUserInfo(DtoUserInfo entity, int type, string viewRootCode)
        {
            using (var scope = this._repo.BeginConnectionScope())
            {
                bool inView = await this._orgService.CheckOrgCodeInView(entity.OrgCode, viewRootCode);

                if (!inView)
                {
                    throw new BizException("没有相应的权限");
                }

                if (type == 1) // 新增
                {
                    // 校验
                    bool result = await this._repo.CheckUserId(entity.UserUid);

                    if (!result)
                    {
                        return(-1);
                    }
                }
                IOrganization pOrg = await this._orgService.GetOrgInfo(entity.OrgCode);

                if (pOrg == null)
                {
                    throw new BizException("父组织不存在,请检查后重新保存");
                }

                entity.OrgName = pOrg.OrgName;

                if (string.IsNullOrEmpty(entity.ViewRootCode))
                {
                    entity.ViewRootCode = entity.OrgCode;
                    entity.ViewRootName = entity.OrgName;
                }
                else if (entity.ViewRootCode == "000000")
                {
                    entity.ViewRootName = "根组织";
                }
                else
                {
                    IOrganization rOrg = await this._orgService.GetOrgInfo(entity.ViewRootCode);

                    if (rOrg == null)
                    {
                        throw new BizException("组织范围顶组织代码不存在,请检查后重试");
                    }
                    entity.ViewRootName = rOrg.OrgName;
                }

                if (type == 1)                   // 新增
                {
                    if (entity.AccountType == 0) //外部用户
                    {
                        if (string.IsNullOrEmpty(entity.Password))
                        {
                            throw new BizException("初始密码不能为空");
                        }

                        entity.Password = CryptographyManager.Md5Encrypt(entity.UserUid + entity.Password);
                    }
                    else
                    {
                        entity.Password = "";
                    }

                    await this._repo.AddUser(entity);

                    return(1);
                }
                else
                {
                    return(await this._repo.UpdateUser(entity));
                }
            }
        }
示例#13
0
        private static Dictionary <Type, object> GetDummiesDictionary()
        {
            #region Funds
            DtoFunds dtoFunds = new DtoFunds {
                Btc = 1.0m, Eur = 1.0m, Ftc = 1.0m, Ltc = 1.0m, Nmc = 1.0m, Nvc = 1.0m, Ppc = 1.0m, Rur = 1.0m, Trc = 1.0m, Usd = 1.0m
            };
            #endregion

            #region DtoRights
            DtoRights dtoRights = new DtoRights {
                Info = true, Trade = true, Withdraw = true
            };
            #endregion

            #region DtoUserInfo
            DtoUserInfo dtoUserInfo = new DtoUserInfo
            {
                Funds      = dtoFunds,
                Rights     = dtoRights,
                OpenOrders = 2,
                ServerTime = 123456798
            };
            #endregion

            #region DtoTicker
            DtoTicker dtoTicker = new DtoTicker
            {
                Average    = 10m,
                Buy        = 9m,
                High       = 11m,
                Last       = 10.50m,
                Low        = 8m,
                Sell       = 7m,
                ServerTime = 123456
            };
            #endregion

            #region DtoCancelOrderAnswer
            DtoCancelOrderAnswer dtoCancelOrderAnswer = new DtoCancelOrderAnswer
            {
                Funds   = dtoFunds,
                OrderId = 100
            };
            #endregion

            #region DtoOrderInfo
            DtoOrderInfo dtoOrderInfo = new DtoOrderInfo
            {
                Amount = 5,
                Price  = 2
            };
            #endregion

            #region DtoDepth
            DtoDepth dtoDepth = new DtoDepth
            {
                Asks = new List <DtoOrderInfo> {
                    dtoOrderInfo, dtoOrderInfo
                },
                Bids = new List <DtoOrderInfo> {
                    dtoOrderInfo
                }
            };
            #endregion

            #region DtoOrder
            DtoOrder dtoOrder = new DtoOrder
            {
                Amount           = 5,
                Pair             = Pair.btc_eur,
                Rate             = 100,
                Status           = 1,
                TimestampCreated = 123456,
                Type             = TradeType.buy
            };
            #endregion

            #region DtoActiveOrders
            DtoActiveOrders dtoActiveOrders = new DtoActiveOrders
            {
                List = new Dictionary <int, DtoOrder> {
                    { 123456789, dtoOrder }
                }
            };

            DummyDtoActiveOrders dummyDtoActiveOrders = new DummyDtoActiveOrders
            {
                List = null
            };
            #endregion

            #region DtoTrade
            DtoTrade dtoTrade = new DtoTrade
            {
                Amount      = 10,
                IsYourOrder = true,
                OrderId     = 123456,
                Pair        = Pair.eur_usd,
                Rate        = 50,
                Timestamp   = 11545,
                Type        = TradeType.sell
            };
            #endregion

            #region DtoTradeAnswer
            DtoTradeAnswer dtoTradeAnswer = new DtoTradeAnswer
            {
                Funds    = dtoFunds,
                OrderId  = 123456,
                Received = 10,
                Remains  = 10
            };
            #endregion

            #region DtoTradeHistory
            DtoTradeHistory dtoTradeHistory = new DtoTradeHistory
            {
                List = new Dictionary <int, DtoTrade> {
                    { 123456, dtoTrade }
                }
            };
            #endregion

            #region DtoTradeInfo
            DtoTradeInfo dtoTradeInfo = new DtoTradeInfo
            {
                Amount        = 15,
                Date          = DateTime.Now,
                Item          = Currency.eur,
                Price         = 100,
                PriceCurrency = Currency.ltc,
                Tid           = 150
            };
            #endregion

            #region DtoTransaction
            DtoTransaction dtoTransaction = new DtoTransaction
            {
                Amount      = 10,
                Currency    = Currency.eur,
                Description = "description",
                Status      = 1,
                Timestamp   = 4587,
                Type        = 1
            };
            #endregion

            #region DtoTransHistory
            DtoTransHistory dtoTransHistory = new DtoTransHistory
            {
                List = new Dictionary <int, DtoTransaction> {
                    { 132456, dtoTransaction }
                }
            };
            #endregion

            Dictionary <Type, Object> dummiesDictionary = new Dictionary <Type, object>
            {
                { typeof(DtoFunds), dtoFunds },
                { typeof(DtoRights), dtoRights },
                { typeof(DtoUserInfo), dtoUserInfo },
                { typeof(DtoTicker), dtoTicker },
                { typeof(DtoCancelOrderAnswer), dtoCancelOrderAnswer },
                { typeof(DtoOrderInfo), dtoOrderInfo },
                { typeof(DtoDepth), dtoDepth },
                { typeof(DtoOrder), dtoOrder },
                { typeof(DtoActiveOrders), dtoActiveOrders },
                { typeof(DummyDtoActiveOrders), dummyDtoActiveOrders },
                { typeof(DtoTrade), dtoTrade },
                { typeof(DtoTradeAnswer), dtoTradeAnswer },
                { typeof(DtoTradeHistory), dtoTradeHistory },
                { typeof(DtoTradeInfo), dtoTradeInfo },
                { typeof(DtoTransaction), dtoTransaction },
                { typeof(DtoTransHistory), dtoTransHistory }
            };

            return(dummiesDictionary);
        }