示例#1
0
        public Result <Payment> Save(Payment Payment)
        {
            var result = new Result <Payment>();

            try
            {
                string query = "select * from Payment where UserId=" + Payment.Id;
                var    dt    = DataAccess.GetDataTable(query);

                if (dt == null || dt.Rows.Count == 0)
                {
                    // Payment.UserId = GetID();
                    query = "insert into Payment values(" + Payment.Id + "," + Payment.OUserId + "," + Payment.WUserId + "," + Payment.Balance + ")";
                }
                else
                {
                    query = "update Payment set Balance=" + Payment.Balance + " where UserId=" + Payment.Id;
                }

                //if (!IsValid(Payment, result))
                //{
                //    return result;
                //}

                result.HasError = DataAccess.ExecuteQuery(query) <= 0;

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = Payment;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
示例#2
0
        private bool IsValid(Payment obj, Result <Payment> result)
        {
            if (!ValidationHelper.IsStringValid(obj.OUserId.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid OUserId";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.WUserId.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid WUserId";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.Balance.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid Balance";
                return(false);
            }


            return(true);
        }
示例#3
0
        public List <Payment> GetAll()
        {
            var result = new List <Payment>();

            try
            {
                string query = "select * from Payment";
                var    dt    = DataAccess.GetDataTable(query);

                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Payment u = ConvertToEntity(dt.Rows[i]);
                        result.Add(u);
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }