示例#1
0
        /// <summary>
        /// Updates user information into the database and the profile picture.
        /// </summary>
        /// <param name="userID">A string containing phone number as user id.</param>
        /// <param name="name">A string containing the name of the user.</param>
        /// <param name="fileData">A base64 encoded string containing the file data.</param>
        /// <returns>true if information is successfully updated; otherwise, false.</returns>
        public bool UpdateUserInformation(string userID, string name, string fileData)
        {
            bool isCompletedSuccessfully = false;

            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                    "Request ===> userID : " + userID + ", name : " + name +
                    ", fileData : " + fileData);
            }

            #endregion

            if (!NeeoUtility.IsNullOrEmpty(userID))
            {
                if (name != null)
                {
                    NeeoUser user = new NeeoUser(userID);
                    try
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            if (user.UpdateUsersDisplayName(name))
                            {
                                if (!NeeoUtility.IsNullOrEmpty(fileData))
                                {
                                    File file = new File()
                                    {
                                        FileName  = NeeoUtility.ConvertToFileName(userID),
                                        Data      = fileData,
                                        FileOwner = userID,
                                        MediaType = MediaType.Image,
                                        MimeType  = MimeType.Image_jpeg
                                    };
                                    if (user.UploadFile(file, FileClassfication.Profile))
                                    {
                                        isCompletedSuccessfully = true;
                                        scope.Complete();
                                    }
                                }
                                else
                                {
                                    isCompletedSuccessfully = true;
                                    scope.Complete();
                                }
                            }
                            else
                            {
                                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidUser);
                            }
                        }
                        return(isCompletedSuccessfully);
                    }
                    catch (ApplicationException appExp)
                    {
                        NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                    }
                    catch (Exception exp)
                    {
                        LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.UnknownError);
                    }
                    return(isCompletedSuccessfully);
                }
                else
                {
                    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
                }
            }
            else
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            }
            return(isCompletedSuccessfully);
        }