示例#1
0
        /// <summary>
        /// This method creates a user/expert into the system
        /// and then creates the session for the user to log in.
        /// </summary>
        /// <param name="firstName">string</param>
        /// <param name="lastName">string</param>
        /// <param name="displayName">string</param>
        /// <param name="emailID">string</param>
        /// <param name="isUser">string</param>
        /// <param name="isExpert">string</param>
        /// <param name="catsubcat">string</param>
        /// <param name="area">string</param>
        /// <param name="city">string</param>
        /// <param name="password">string</param>
        /// <param name="deviceTokenId">string</param>
        /// <returns>SessionResponseObject</returns>
        public ResponseObjectForAnything CreateUser(string firstName, string lastName, string displayName, string emailID, string address2, string city, string pinCode,
                                                    string isUser, string isExpert, string catsubcat, string password, string deviceTokenId)
        {
            AuthenticationEngine authEngine = new AuthenticationEngine();
            int userId = -1;
            SessionResponseObject sessionObject = new SessionResponseObject();
            ResponseObjectForAnything responseObject = new ResponseObjectForAnything();

            try
            {
                string useraccount = authEngine.CheckExistingAccount(emailID);

                if (useraccount == "SUCCESS")
                {
                    Database db = DatabaseFactory.CreateDatabase();
                    DbCommand dbCommand = db.GetStoredProcCommand("usp_CreateUser");

                    db.AddInParameter(dbCommand, "FirstName", DbType.String, firstName);
                    db.AddInParameter(dbCommand, "LastName", DbType.String, lastName);
                    db.AddInParameter(dbCommand, "DisplayName", DbType.String, displayName);
                    db.AddInParameter(dbCommand, "EmailID", DbType.String, emailID);
                    db.AddInParameter(dbCommand, "Address2", DbType.String, address2);
                    db.AddInParameter(dbCommand, "City", DbType.String, city);
                    db.AddInParameter(dbCommand, "PinCode", DbType.String, pinCode);
                    float latitude, longitude;
                    GeoHelper geoHelper = new GeoHelper();
                    geoHelper.GetGeoLocationByPinCode(pinCode, out latitude, out longitude);
                    db.AddInParameter(dbCommand, "Latitude", DbType.Decimal, latitude);
                    db.AddInParameter(dbCommand, "Longitude", DbType.Decimal, longitude);
                    db.AddInParameter(dbCommand, "IsUser", DbType.Boolean, Convert.ToBoolean(isUser));
                    db.AddInParameter(dbCommand, "IsExpert", DbType.Boolean, Convert.ToBoolean(isExpert));
                    string[] lstcatsubcat = catsubcat.Split(";".ToCharArray());
                    DataSet dataSet = new DataSet();
                    DataTable dataTable = dataSet.Tables.Add();
                    dataTable.Columns.Add("CategoryID");
                    dataTable.Columns.Add("SubCategoryID");
                    for(int count =0; count <lstcatsubcat.Length - 1; count++)
                    {
                        string category = lstcatsubcat[count].Split(",".ToCharArray())[0];
                        string subcategory = lstcatsubcat[count].Split(",".ToCharArray())[1];
                        dataTable.Rows.Add(new object[] { category, subcategory });
                    }
                    db.AddInParameter(dbCommand, "CatSubCat", DbType.String, dataSet.GetXml());
                    db.AddInParameter(dbCommand, "Password", DbType.String, BitConverter.ToString(SHA1.Create().ComputeHash(Encoding.Default.GetBytes(password + ""))).Replace("-", ""));
                    db.AddInParameter(dbCommand, "DeviceTokenId", DbType.String, deviceTokenId);

                    userId = Int32.Parse(db.ExecuteScalar(dbCommand).ToString());

                    responseObject.ResultCode = "SUCCESS";
                    responseObject.ResultObjectJSON = Serializer.ObjectToJSON(sessionObject);
                    responseObject.ResultObjectRecordCount = userId;
                    if (responseObject.ResultObjectRecordCount <= 0) { responseObject.ResultMessage = "Email Id already exists."; }
                }
                else
                {
                    responseObject.ResultCode = "ERROR";
                    responseObject.ResultMessage = "Email Id already exists.";
                }
            }
            catch (Exception ex)
            {
                responseObject.ResultCode = "ERROR";
                responseObject.ResultMessage = ex.Message;
                CustomException exc = new CustomException(ex.ToString(), this.ToString(), "CreateUser", System.DateTime.Now);
                ExceptionManager.PublishException(exc);
            }
            return (responseObject);
        }