Beispiel #1
0
        public IAccountResult CreateItem(IAccount model)
        {
            IAccountResult accountResult;
            var            conn = _connectionFactory.GetConnection();

            model.DateCreated = DateTime.Now;

            var sql = "INSERT INTO Accounts (UserId, Name, Description, DateCreated, IsActive) " +
                      "VALUES (@UserId, @Name, @Description, @DateCreated, @IsActive);" +
                      "SELECT CAST(SCOPE_IDENTITY() AS INT)";

            var temp = conn.Query <int>(sql, model).Single();

            model.AccountId = temp;

            if (temp > 0)
            {
                accountResult      = new AccountSuccessResult();
                accountResult.Item = model;
            }
            else
            {
                accountResult = new AccountFailureResult();
            }


            return(accountResult);
        }
Beispiel #2
0
        public IAccountResult DeleteItem(IAccount model)
        {
            IAccountResult accountResult;

            using (var conn = _connectionFactory.GetConnection())
            {
                var result = conn.Delete(model);

                if (result == true)
                {
                    accountResult = new AccountSuccessResult();
                }
                else
                {
                    accountResult = new AccountFailureResult();
                }
            }

            return(accountResult);
        }
Beispiel #3
0
        protected IAccountResult CreateItem(IAccount model)
        {
            IAccountResult result;

            var validationErrors = _validator.Validate(model).ToList();

            if (validationErrors.Count == 0)
            {
                result = _repository.CreateItem(model);
            }
            else
            {
                result = new AccountFailureResult()
                {
                    Item = model
                };
                ((List <string>)result.Data).AddRange(validationErrors);
            }

            return(result);
        }
Beispiel #4
0
        public IAccountResult UpdateItem(IAccount model)
        {
            IAccountResult accountResult;

            using (var conn = _connectionFactory.GetConnection())
            {
                var result = conn.Update(model);

                if (result == true)
                {
                    accountResult      = new AccountSuccessResult();
                    accountResult.Item = model;
                }
                else
                {
                    accountResult = new AccountFailureResult();
                    accountResult.AddData("Unable to update account Id " + model.AccountId);
                }
            }

            return(accountResult);
        }
Beispiel #5
0
        public IAccountResult GetItem(int key)
        {
            IAccountResult accountResult;

            using (var conn = _connectionFactory.GetConnection())
            {
                var result = conn.Get <IAccount>(new AccountDTO {
                    AccountId = key
                });

                if (result != null)
                {
                    accountResult      = new AccountSuccessResult();
                    accountResult.Item = result;
                }
                else
                {
                    accountResult = new AccountFailureResult();
                    accountResult.AddData("Unable to locate account Id " + key);
                }
            }

            return(accountResult);
        }