示例#1
0
        /// <summary>
        /// Проверяем и сохраняем логин.
        /// </summary>
        public LoginOutEntity Insert(LoginInEntity login)
        {
            string error = CheckEmail(login.Email);

            error += CheckUniqueEmail(login.Email);
            error += CheckName(login.Name);
            error += CheckPassword(login.Password);

            if (!String.IsNullOrEmpty(error))
            {
                throw new MyException(error);
            }

            Login dataLogin = new Login(login.Name, login.Email, login.Password);

            repositories.Login.Save(dataLogin);
            CreateStartBalance(dataLogin);
            repositories.Save();

            return(Translate(dataLogin));
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        public TransactionOutEntity Insert(TransactionInEntity transaction, LoginOutEntity currentLogin)
        {
            if (currentLogin == null)
            {
                throw new MyException("You must registration");
            }
            if (string.IsNullOrEmpty(transaction.ToLogin))
            {
                throw new MyException("You must select the payment receiver");
            }

            if (transaction.Amount <= 0)
            {
                throw new MyException("The amount must be greater than 0");
            }

            ILoginService loginService = AppKernel.Get <ILoginService>(new[] {
                new ConstructorArgument("repositories", repositories)
            });;

            LoginOutEntity fromLogin = loginService.GetByMail(currentLogin.Email);

            if (!loginService.CheckEnough(fromLogin, transaction.Amount))
            {
                throw new MyException("Not enough funds");
            }

            LoginOutEntity toLogin = loginService.GetByMail(transaction.ToLogin);

            Transaction newTransaction = new Transaction(DateTime.Now, fromLogin.Id, toLogin.Id, transaction.Amount);

            repositories.Transaction.Save(newTransaction);
            repositories.Save();

            return(Translate(newTransaction));
        }
示例#3
0
 public void Save()
 {
     _repo.Save();
 }