Exemple #1
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);
            }
        }
Exemple #2
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));
        }
Exemple #3
0
        public UserRegistrationStatusDTO AddProject(string partnerName, UserDetailsTDO user)
        {
            UserRegistrationStatusDTO retObj = new UserRegistrationStatusDTO();

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

                // additional user info
                List <KeyValuePair <string, string> > additionalData =
                    (from T in request.Headers.AllKeys
                     where T.ToLower().StartsWith("form-data-")
                     select new KeyValuePair <string, string>(
                         T.Substring(10),
                         request.Headers[T].ToString()
                         )).ToList();

                // Register User
                int    dbErrorCode;
                string dbErrorMsg;
                int    userId = UserDetailsFacade.RegisterUser(user, partnerName, additionalData, requestIpAddress, out dbErrorCode, out dbErrorMsg);

                if (userId != -1)
                {
                    retObj.UserId  = userId;
                    retObj.Status  = true;
                    retObj.Message = string.Empty;
                }
                else if (dbErrorCode == 0 && !string.IsNullOrEmpty(dbErrorMsg))
                {
                    retObj.Message = dbErrorMsg;
                }
                else
                {
                    throw new Exception(string.Format("UserRegistration() - Database ERROR: ErrorCode: {0}, ErrorMsg: {1}", dbErrorCode, dbErrorMsg));
                }
            }
            catch (Exception exc)
            {
                log.Error(exc);
                retObj = new UserRegistrationStatusDTO();
            }

            return(retObj);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        public static UserDetailsTDO GetUserFullProfile(int userId)
        {
            UserDetailsTDO retVal = null;

            try
            {
                DataSet ds = new UserDB(Utility.ConfigurationHelper.GPD_Connection).GetUserFullProfile(userId);

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    retVal = new UserDetailsTDO()
                    {
                        FirstName = ds.Tables[0].Rows[0]["first_name"].ToString(),
                        LastName  = ds.Tables[0].Rows[0]["last_name"].ToString(),
                        Email     = ds.Tables[0].Rows[0]["email"].ToString(),
                        JobTitle  = ds.Tables[0].Rows[0]["job_title"].ToString(),
                        Phone     = ds.Tables[0].Rows[0]["business_phone"].ToString(),
                    };

                    if (ds.Tables.Count > 1 && ds.Tables[1].Rows.Count > 0)
                    {
                        retVal.CompanyDetails = new CompanyDetailsDTO()
                        {
                            Id              = (int)ds.Tables[1].Rows[0]["firm_id"],
                            Name            = ds.Tables[1].Rows[0]["name"].ToString(),
                            WebSite         = ds.Tables[1].Rows[0]["url"].ToString(),
                            Country         = ds.Tables[1].Rows[0]["country"].ToString(),
                            Address         = ds.Tables[1].Rows[0]["address_line_1"].ToString(),
                            Address2        = ds.Tables[1].Rows[0]["address_line_2"].ToString(),
                            City            = ds.Tables[1].Rows[0]["city"].ToString(),
                            State           = ds.Tables[1].Rows[0]["state_province"].ToString(),
                            PostalCode      = ds.Tables[1].Rows[0]["zip_postal_code"].ToString(),
                            DefaultIndustry = ds.Tables[1].Rows[0]["DefaultIndustry"].ToString()
                        };
                    }
                }
                ;
            }
            catch (Exception ex)
            {
                log.Error("Unable to get user full profile for id: " + userId, ex);
            }

            return(retVal);
        }
Exemple #5
0
        public ServiceEntities.ResponseEntities.UpdateUserResponse UpdateUser(UserDetailsTDO userDetails)
        {
            GPD.ServiceEntities.ResponseEntities.UpdateUserResponse retObj = new GPD.ServiceEntities.ResponseEntities.UpdateUserResponse(false, -1);

            try
            {
                var request = HttpContext.Current.Request;
                var userId  = int.Parse(request.Headers["user-id"]);
                retObj.UserId = userId;

                // update user profile
                string errorMsg;
                retObj.Status = UserDetailsFacade.UpdatetUserProfile(userId, userDetails, out errorMsg);
            }
            catch (Exception exc)
            {
                log.Error(exc);
                retObj = new GPD.ServiceEntities.ResponseEntities.UpdateUserResponse(false, -1);
            }

            return(retObj);
        }
Exemple #6
0
        public UpdateUserProfileStatusDTO UpdateUserProfile(UserDetailsTDO userDetails)
        {
            UpdateUserProfileStatusDTO retObj = new UpdateUserProfileStatusDTO()
            {
                Message = "Request Not Authenticated."
            };

            try
            {
                var request       = HttpContext.Current.Request;
                var authHeader    = request.Headers["Authorization"];
                var authHeaderVal = System.Net.Http.Headers.AuthenticationHeaderValue.Parse(authHeader);

                if (authHeaderVal.Scheme.Equals("basic", StringComparison.OrdinalIgnoreCase) && authHeaderVal.Parameter != null)
                {
                    string credentials  = Encoding.GetEncoding("iso-8859-1").GetString(Convert.FromBase64String(authHeaderVal.Parameter));
                    string userEmail    = credentials.Substring(0, credentials.IndexOf(':'));
                    string userPassword = credentials.Substring(credentials.IndexOf(':') + 1);

                    int userId = -1;
                    var result = UserDetailsFacade.AuthenticateUser(userEmail, userPassword, out userId);

                    if (userId != -1)
                    {
                        // update user profile
                        string errorMsg;
                        retObj.Status  = UserDetailsFacade.UpdatetUserProfile(userId, userDetails, out errorMsg);
                        retObj.Message = errorMsg;
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error(exc);
            }

            return(retObj);
        }
Exemple #7
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);
        }