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)); }
public HttpResponseMessage Logout(int userId) { 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 { retVal = bl.Logout(userId); } var status = HttpStatusCode.OK; if (retVal.Message != "OK") { status = HttpStatusCode.InternalServerError; } return(new HttpResponseMessage(status) { Content = new StringContent(JsonConvert.SerializeObject(retVal), Encoding.UTF8, "application/json") }); } catch (Exception ex) { return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(JsonConvert.SerializeObject(ex), Encoding.UTF8, "application/json") }); } }