示例#1
0
        public int InsertOrUpdateUser(UserInfoFilter userInfo)
        {
            IDataReader dataReader = null;

            try
            {
                Database db = DatabaseFactory.CreateDatabase("DbConnection");

                int currentDate = 0;
                int currentTime = 0;
                Common.GetCurrentDateTime(out currentDate, out currentTime);

                dataReader = BillingDAL.CheckUserNameExists(db, userInfo.UserID, userInfo.UserName);
                if (dataReader.Read())
                {
                    dataReader.Close();
                    return(-1); //username already exists
                }
                else
                {
                    dataReader.Close();
                    if (userInfo.UserID > 0)
                    {
                        BillingDAL.UpdateUser(db, userInfo.UserID, userInfo.Password, userInfo.FirstName, userInfo.LastName, userInfo.LoginUserID, currentDate, currentTime);
                        return(userInfo.UserID);
                    }
                    else
                    {
                        return(BillingDAL.InsertUser(db, userInfo.UserName, userInfo.Password, userInfo.FirstName, userInfo.LastName, userInfo.LoginUserID, currentDate, currentTime));
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
                throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError);
            }
            finally
            {
                if (dataReader != null && !dataReader.IsClosed)
                {
                    dataReader.Close();
                }
            }
        }