Ejemplo n.º 1
0
        public void Add_New_Account()
        {
            using var dbContext = new TinyBankDBContext(GetDBOptions().Options);

            var account = new Accounts()
            {
                State = AccountStateTypes.Active,
                AccountDescription = "My Personal Account",
                AccountNumber      = "1558642182",
                Currency           = "EUR",
                Balance            = 1500.0m
            };

            dbContext.Add(account);
            dbContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Add_New_Customer()
        {
            using var dbContext = new TinyBankDBContext(GetDBOptions().Options);

            var customer = new Customer()
            {
                Active     = true,
                Address    = "Test Address",
                CustBankID = "032846778",
                CustType   = CustomerType.Personal,
                Name       = "Kostas",
                SureName   = "Parginos",
                VatNumber  = "123456789"
            };

            dbContext.Add(customer);
            dbContext.SaveChanges();
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Adds a new customer
        /// </summary>
        /// <param name="options">RegisterCustomerOptions</param>
        /// <returns>
        ///     Result.Code should be Success(200)
        ///     Check Result.Code and Result.Message to get more details about possible errors
        /// </returns>
        public Result <Customer> Register(RegisterCustomerOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.Name))
            {
                return new Result <Customer>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = $"Customer name is empty!"
                       }
            }
            ;

            if (string.IsNullOrWhiteSpace(options.SureName))
            {
                return new Result <Customer>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = $"Customer sure name is empty!"
                       }
            }
            ;

            var validVatNumber = IsValidVatNumber(options.CountryCode, options.VATNumber);

            if (!validVatNumber.IsSuccess())
            {
                return(new Result <Customer>()
                {
                    Code = validVatNumber.Code,
                    Message = validVatNumber.Message
                });
            }

            if (_dbContext.Set <Customer>()
                .Any(c => c.VatNumber == options.VATNumber))
            {
                return(new Result <Customer>()
                {
                    Code = ResultCodes.BadRequest,
                    Message = $"Specific Vat Number {options.VATNumber} already exists!"
                });
            }

            var customer = new Customer()
            {
                Name       = options.Name,
                SureName   = options.SureName,
                VatNumber  = options.VATNumber,
                CustBankID = options.CustomerBankID,
                CustType   = options.CustType,
                Address    = options.Address
            };

            _dbContext.Add <Customer>(customer);
            _dbContext.SaveChanges();

            return(new Result <Customer>()
            {
                Code = ResultCodes.Success,
                Data = customer
            });
        }