Beispiel #1
0
        public static int RegisterUser(UserDetailsTDO userDetails, string partnerName, List <KeyValuePair <string, string> > additionalData,
                                       string requestIpAddress, out int dbErrorCode, out string dbErrorMsg)
        {
            dbErrorCode = -1;
            dbErrorMsg  = "";

            if (string.IsNullOrWhiteSpace(userDetails.CompanyDetails.Name))
            {
                userDetails.CompanyDetails = new CompanyDetailsDTO();
            }

            if (string.IsNullOrWhiteSpace(userDetails.Password))
            {
                dbErrorCode = 0;
                dbErrorMsg  = "Unable to register user at this time. Invalid Password.";
                return(-1);
            }


            // hash user password
            userDetails.Password = ValueHashUtil.CreateHash(userDetails.Password);

            // get XML based on UserRegistrationDTO object
            XDocument xDoc = new XDocument();

            using (var writer = xDoc.CreateWriter())
            {
                var serializer = new DataContractSerializer(userDetails.GetType());
                serializer.WriteObject(writer, userDetails);
            }

            // additional user info
            if (additionalData != null && additionalData.Count > 0)
            {
                XNamespace xNamespace = xDoc.Root.Attribute("xmlns").Value;

                xDoc.Root.LastNode.AddAfterSelf(new XElement(xNamespace + "additional-data",
                                                             from T in additionalData
                                                             select new XElement(xNamespace + "item",
                                                                                 new XAttribute("type", T.Key),
                                                                                 T.Value
                                                                                 )));
            }

            // db call
            return(new ProjectDB(ConfigurationHelper.GPD_Connection).AddUserDetails(xDoc, requestIpAddress, out dbErrorCode, out dbErrorMsg));
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userDetails"></param>
        public static bool UpdatetUserProfile(int userId, UserDetailsTDO userDetails, out string errorMsg)
        {
            try
            {
                // hash user password
                userDetails.Password = (string.IsNullOrEmpty(userDetails.Password)) ? null : ValueHashUtil.CreateHash(userDetails.Password);

                // get XML based on UserDetailsTDO object
                XDocument xDoc = new XDocument();
                using (var writer = xDoc.CreateWriter())
                {
                    var serializer = new System.Runtime.Serialization.DataContractSerializer(userDetails.GetType());
                    serializer.WriteObject(writer, userDetails);
                }

                // update user details
                int errorCode;
                new ProjectDB(ConfigurationHelper.GPD_Connection).UpdateUserProfile(userId, xDoc, out errorCode, out errorMsg);
                return(errorCode == 0);
            }
            catch (Exception exc)
            {
                log.Error("Unable to Update User Profile. ERROR: " + exc.ToString());
                errorMsg = "Unable to Update User Profile";
                return(false);
            }
        }
Beispiel #3
0
        //[ApiExplorerSettings(IgnoreApi = true)]
        public UserRegistrationStatusDTO RegisterUser(UserDetailsTDO user)
        {
            UserRegistrationStatusDTO retVal = new UserRegistrationStatusDTO()
            {
                Status = false
            };
            XDocument xDoc = new XDocument();
            int       errorCode;
            string    errorMsg, requestIpAddress = string.Empty;

            try
            {
                if (string.IsNullOrWhiteSpace(user.CompanyDetails.Name))
                {
                    user.CompanyDetails = new CompanyDetailsDTO();
                }

                // get XML based on UserRegistrationDTO object
                using (var writer = xDoc.CreateWriter())
                {
                    var serializer = new DataContractSerializer(user.GetType());
                    serializer.WriteObject(writer, user);
                }

                try
                {
                    // get requestIP address
                    requestIpAddress = HttpContext.Current.Request.UserHostAddress;

                    // additional user info
                    XNamespace xNamespace = xDoc.Root.Attribute("xmlns").Value;
                    var        request    = HttpContext.Current.Request;

                    xDoc.Root.LastNode.AddAfterSelf(new XElement(xNamespace + "additional-data",
                                                                 from T in request.Headers.AllKeys.Where(T => T.StartsWith("form-data-")).ToList()
                                                                 select new XElement(xNamespace + "item",
                                                                                     new XAttribute("type", T.Substring(10)),
                                                                                     request.Headers[T].ToString()
                                                                                     )));
                }
                catch { }

                // add a user to repository
                int userId = UserDetailsFacade.AddUserDetails(xDoc, requestIpAddress, out errorCode, out errorMsg);

                if (userId != -1)
                {
                    retVal = new UserRegistrationStatusDTO()
                    {
                        UserId = userId,
                        Status = true
                    };

                    return(retVal);
                }

                if (errorCode == 0 && !string.IsNullOrEmpty(errorMsg))
                {
                    retVal.Message = errorMsg;
                }
                else
                {
                    throw new Exception(string.Format("Add new UserDeatils() - Database ERROR: ErrorCode: {0}, ErrorMsg: {1}", errorCode, errorMsg));
                }
            }
            catch (Exception exc)
            {
                log.Error(exc);
                retVal.Message = "The server encountered an error processing registration. Please try again later.";
            }

            return(retVal);
        }