Пример #1
0
        public HttpResponseMessage UpdateUser(HttpRequestMessage requestUpdate)
        {
            if (Request.Method == HttpMethod.Options)
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }

            WebServiceResult retVal = new WebServiceResult()
            {
                Message = "OK", Result = ""
            };
            UserBusinessLayer bl = new UserBusinessLayer();

            try
            {
                if (!bl.CheckSession(new Guid(Utils.GetSessionId())))
                {
                    retVal.Message = "Session error";
                    retVal.Result  = "Invalid session";
                }
                else
                {
                    string[] json = requestUpdate.Content.ReadAsStringAsync().Result.Split('=');

                    Dictionary <string, string> result = new Dictionary <string, string>();
                    if (json[0] != null && json[0] == "data")
                    {
                        result = JsonConvert.DeserializeObject <Dictionary <string, string> >(HttpUtility.UrlDecode(json[1]));
                        retVal = bl.UpdateUser(result);
                    }
                    else
                    {
                        retVal = new WebServiceResult()
                        {
                            Message = "POST request parameters error!", Result = "No 'data' parameter"
                        };
                    }
                }
            }

            catch (Exception ex)
            {
                retVal = new WebServiceResult()
                {
                    Message = "POST request parameters error!", Result = String.Format("Message: {0}, StackTrace: {1}", ex.Message, ex.StackTrace)
                };
            };

            HttpStatusCode status = HttpStatusCode.OK;

            if (retVal.Message != "OK")
            {
                status = HttpStatusCode.InternalServerError;
            }
            return(Request.CreateResponse(status, retVal));
        }