/// <summary> /// /// </summary> public void Create() { Account accauntEntity = new Account(); accauntEntity.accountId = Guid.NewGuid(); accauntEntity.balance = 0.00m; accauntEntity.currency = 0; accauntEntity.activePlan = (int)AccountTypes.Free; unitOfWork.RepositoryFor<Account>().Add(accauntEntity); unitOfWork.Commit(); }
/// <summary> /// Списание денежных средств /// decrease /// </summary> /// <param name="account"></param> /// <param name="amount"></param> public void Debit(Account account, decimal amount) { //if (IsSufficient(account, amount)) //{ // TableTransaction transactionEntity = new TableTransaction(); // transactionEntity.TransactionId = Guid.NewGuid(); // transactionEntity.Amount = amount; // transactionEntity.Currency = 0; // transactionEntity.DateOperation = DateTime.Now; // m_unitOfWork.RepositoryFor<TableTransaction>().Add(transactionEntity); // account.Balance -= amount; // account.Transactions = new List<TableTransaction> { transactionEntity }; // m_unitOfWork.RepositoryFor<TableAccount>().Modified(account); // m_unitOfWork.Commit(); //} }
/// <summary> /// /// </summary> /// <param name="account"></param> /// <param name="amount"></param> /// <returns></returns> private bool IsSufficient(Account account, decimal amount) { if (account.balance > amount) { return true; } return false; }
/// <summary> /// Создает и добавляет в базу данных нового пользователя /// </summary> /// <param name="userId">Идентификатор пользователя</param> /// <param name="referrerId">Идентификатор пригласившего в систему реферера</param> /// <param name="username">Псевдоним пользователя</param> /// <param name="email">Адрес электронной почты</param> /// <param name="password">Пароль</param> /// <returns></returns> public void Create(Guid userId, Guid? referrerId, string username, string email, string password) { #region Role Role roleEntity = unitOfWork.RepositoryFor<Role>().Single(i => i.name == "guest"); #endregion #region Account Account accountEntity = new Account(); accountEntity.accountId = Guid.NewGuid(); accountEntity.balance = 0.00M; accountEntity.currency = 0; accountEntity.activePlan = (int)AccountTypes.Free; unitOfWork.RepositoryFor<Account>().Add(accountEntity); #endregion #region Profile Profile profileEntity = new Profile(); profileEntity.profileId = Guid.NewGuid(); profileEntity.name = string.Empty; profileEntity.nameVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.gender = (int)GenderTypes.Unspecified; profileEntity.genderVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.birthdate = DateTime.Now; profileEntity.birthdateVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.avatar = "/Assets/Images/noavatar.gif"; //profileEntity.Location = locationEntity; profileEntity.status = (int)ProfileTypes.Active; profileEntity.level = 0; profileEntity.karma = 0; unitOfWork.RepositoryFor<Profile>().Add(profileEntity); //m_unitOfWork.Commit(); #endregion #region User User userEntity = new User(); userEntity.userId = userId; userEntity.referrerId = referrerId; userEntity.userName = username; userEntity.email = email; userEntity.emailKey = Guid.NewGuid().ToString(); userEntity.passwordSalt = GetPasswordSalt(); userEntity.password = GetPasswordHash(password, userEntity.passwordSalt); userEntity.isLockedOut = false; userEntity.dateCreated = DateTime.Now; userEntity.lastDateLockout = DateTime.Now; /* Дата блокировки аккаута */ userEntity.lastDateLogin = DateTime.Now; /* Дата последнего входа */ userEntity.lastDateModified = DateTime.Now; /* Дата последнего редактировании профиля */ userEntity.lastPasswordDateChanged = DateTime.Now; /* Дата смены пароля */ userEntity.account = accountEntity; userEntity.profile = profileEntity; userEntity.role = roleEntity; unitOfWork.RepositoryFor<User>().Add(userEntity); unitOfWork.Commit(); #endregion }