public IActionResult EditUserInfo(EditUserInfoViewModel model) { var userInfo = _userInfoRepo.Read(_userManager.GetUserId(User)); model.DefaultAvatarPath = _config.GetValue <string>("FileUploadSettings:DefaultAvatarImgFilePath"); if (ModelState.IsValid) { var result = FileProcessing.UploadAvatarPng(model.AvatarImage, _userManager.GetUserName(User), this, _config, _webHostEnvironment); if (result != null) { model.AvatarImgPath = result; // Render on page userInfo.AvatarImgPath = result; //Save in DB } else { model.AvatarImgPath = userInfo.AvatarImgPath; } userInfo.FirstName = model.FirstName; userInfo.MiddelName = model.MiddleName; userInfo.LasttName = model.LastName; userInfo.Summary = model.Summary; //userInfo.MainText = model.MainText; //userInfo.AvailableForContact = model.AvailableForContact; _userInfoRepo.Update(userInfo); return(View(model)); } model = new EditUserInfoViewModel { AvatarImgPath = userInfo.AvatarImgPath, Summary = userInfo.Summary, UserName = _userManager.GetUserName(User) //MainText = userInfo.MainText, //AvailableForContact = userInfo.AvailableForContact }; return(View(model)); }
private void PostAction(HttpListenerContext httpListenerContext, string[] route) { string json; UserInfo user; try { json = ReadJsonContent(httpListenerContext); user = JsonConvert.DeserializeObject <UserInfo>(json); } catch (Exception e) { ErrorResponse .Get(HttpStatusCode.BadRequest) .Handle(httpListenerContext, $"Malformed or bad data provided in Json Body. Details - {e.Message}"); return; } try { switch (route[0]) { case "add": SendResponse(httpListenerContext, userRepo.Insert(user)); break; case "update": SendResponse(httpListenerContext, userRepo.Update(user)); break; default: ErrorResponse .Get(HttpStatusCode.BadRequest) .Handle(httpListenerContext, $"Bad Request - No '/rankings/{string.Join("/", route)}/...' exists"); break; } } catch (Exception) { ErrorResponse.Get(HttpStatusCode.InternalServerError).Handle( httpListenerContext, $"Route - '{string.Join("/", route)}'," + $" Content - '{json}'"); } }