Ejemplo n.º 1
0
        public IActionResult UpdProfile(GetUserVM data)
        {
            var id = HttpContext.Session.GetString("id");

            try
            {
                AuthController controller = new AuthController();
                data.ProfileImages = Path.GetFileName(data.ProfileImages);
                data.Session       = HttpContext.Session.GetString("id");
                var json        = JsonConvert.SerializeObject(data);
                var buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                if (data.Id == id)
                {
                    client.DefaultRequestHeaders.Add("Authorization", HttpContext.Session.GetString("token"));
                    var result = client.PutAsync("users/" + id, byteContent).Result;
                    if (result.IsSuccessStatusCode)
                    {
                        HttpContext.Session.Remove("name");
                        HttpContext.Session.Remove("img");
                        HttpContext.Session.SetString("name", data.Name);
                        HttpContext.Session.SetString("img", data.ProfileImages);
                        controller.SendLogs(HttpContext.Session.GetString("email") + " Update Account", HttpContext.Session.GetString("email"));
                        return(Json(result));
                    }
                    var getdata = result.Content.ReadAsStringAsync().Result;
                    return(Json(new { result, msg = getdata }));
                }

                return(Json(404));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }