Пример #1
0
        public static Dictionary<string, double> DoTransaction(string debtPhoneNo, string creditPhones)
        {
            TransactionManager manager = null;
            bool myManager = false;
            if (manager == null)
            {
                manager = new TransactionManager();
                myManager = true;
            }

            Dictionary<string, double> cisWithDeviceTokens = new Dictionary<string,double>();
            Dictionary<string, double> creditInformation = StringToMap(creditPhones);

            string sql = string.Empty;
            IList<SqlParameter> parms = new List<SqlParameter>();
            parms.Add(new SqlParameter("@FromPhone", debtPhoneNo));
            parms.Add(new SqlParameter("@CreditInfo", ToXml(creditInformation)));

            sql = "dbo.prd_Process_Transaction";

            try
            {
                DataRowCollection tdc = manager.ExecuteQuery(sql, CommandType.StoredProcedure, parms);

                if (myManager)
                    manager.Commit();

                foreach (DataRow dr in tdc)
                {
                    cisWithDeviceTokens.Add(dr["DeviceToken"].ToString().Trim(), Convert.ToDouble(dr["Amount"].ToString().Trim()));
                }

                return cisWithDeviceTokens;
            }
            catch (SqlException se)
            {
                if (se.Message.StartsWith("Violation of PRIMARY KEY constraint") ||
                    se.Message.StartsWith("Violation of UNIQUE KEY constraint"))
                {
                    throw se;
                }
                throw se;
            }
        }
Пример #2
0
        public static User Login(string email, string pass, string deviceToken)
        {
            bool myManager = false;
            TransactionManager manager = null;
            if (manager == null)
            {
                myManager = true;
                manager = new TransactionManager();
            }

            if (!_provider.ValidateUser(email, pass)) throw new Exception("Invalid Username or Password!");

            IList<SqlParameter> parms = new List<SqlParameter>{
                new SqlParameter("@Email", email),
                new SqlParameter("@DeviceToken", deviceToken)
            };

            string sql = "dbo.prd_User_Login";
            User user = null;

            DataRowCollection tdc = manager.ExecuteQuery(sql, CommandType.StoredProcedure, parms); //manager.ExecuteMultiQuery(sql, CommandType.StoredProcedure, parms);

            foreach (DataRow dr in tdc)
            {
                user = User.New();
                user.Email = dr["Email"].ToString().Trim();
                user.FirstName = dr["FirstName"].ToString().Trim();
                user.Surname = dr["Surname"].ToString().Trim();
                user.PhoneNo = dr["PhoneNo"].ToString().Trim();
                user.DeviceToken = dr["DeviceToken"].ToString().Trim();
                user.AgeRange = dr["AgeRange"].ToString().Trim();
                user.Gender = dr["Gender"].ToString().Trim();
            }

            if (myManager)
                manager.Commit();

            return user;
        }
Пример #3
0
        public void Register(TransactionManager manager)
        {
            bool myManager = false;
            if (manager == null)
            {
                manager = new TransactionManager();
                myManager = true;
            }

            string sql = string.Empty;
            IList<SqlParameter> parms = new List<SqlParameter>();
            parms.Add(new SqlParameter("@Email", Email));
            parms.Add(new SqlParameter("@FirstName", FirstName));
            parms.Add(new SqlParameter("@Surname", Surname));
            parms.Add(new SqlParameter("@PhoneNo", PhoneNo));
            parms.Add(new SqlParameter("@DeviceToken", DeviceToken));
            parms.Add(new SqlParameter("@AgeRange", AgeRange));
            parms.Add(new SqlParameter("@Gender", Gender));

            sql = "dbo.prd_User_Register";

            MembershipCreateStatus status;
            try
            {
                _provider.CreateUser(Email, Password, Email, "Question", "Answer", true, Guid.NewGuid(), out status);

                if (!status.Equals(MembershipCreateStatus.Success)) throw new Exception("Registration failed!!");
                manager.ExecuteCommand(sql, CommandType.StoredProcedure, parms);

                if (myManager)
                    manager.Commit();
            }
            catch (SqlException se)
            {
                if (se.Message.StartsWith("Violation of PRIMARY KEY constraint") ||
                    se.Message.StartsWith("Violation of UNIQUE KEY constraint"))
                {
                    //throw new SplitMe.Common.DuplicateException("An Ingredient for this site already exists with that name [" + Name + "]!", se);
                    throw se;
                }
                throw se;
            }
        }