Exemplo n.º 1
0
        public HttpResponseMessage CallingTone([FromBody] Models.CallingTone callingTone)
        {
            callingTone.Uid = callingTone.Uid.Trim();
            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" +
                    "Request ===> " + JsonConvert.SerializeObject(callingTone));
            }

            #endregion

            if (ModelState.IsValid)
            {
                try
                {
                    if (Enum.IsDefined(typeof(Common.CallingTone), callingTone.Tone))
                    {
                        NeeoUser user = new NeeoUser(callingTone.Uid.Trim());
                        if (user.UpdateSettings((Common.CallingTone)callingTone.Tone, ToneType.CallingTone))
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ""));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest));
                    }
                }
                catch (ApplicationException appException)
                {
                    return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt32(appException.Message), ""));
                }
                catch (Exception exception)
                {
                    Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().GetType().Name);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ""));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Tone([FromBody] ToneSetting toneSetting)
        {
            toneSetting.Uid = (toneSetting.Uid != null) ? toneSetting.Uid.Trim() : toneSetting.Uid;
            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + "===>" +
                    "Request ===> " + JsonConvert.SerializeObject(toneSetting));
            }

            #endregion

            //#region user authentication

            //IEnumerable<string> headerValues;
            //string keyFromClient = "";
            //if (Request.Headers.TryGetValues("key", out headerValues))
            //{
            //    keyFromClient = headerValues.First();
            //}

            //if (NeeoUtility.AuthenticateUserRequest(toneSetting.UID, keyFromClient))
            //{
            //    #endregion

            if (ModelState.IsValid)
            {
                try
                {
                    if (Enum.IsDefined(typeof(IMTone), toneSetting.IMTone))
                    {
                        NeeoUser user = new NeeoUser(toneSetting.Uid.Trim());
                        if (user.UpdateSettings((IMTone)toneSetting.IMTone, ToneType.IMTone))
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ""));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest));
                    }
                }
                catch (ApplicationException appException)
                {
                    return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt32(appException.Message), ""));
                }
                catch (Exception exception)
                {
                    Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().GetType().Name);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ""));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            //}
            //else
            //{
            //    return Request.CreateResponse(HttpStatusCode.Unauthorized);
            //}
        }