daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [HttpPut]
  2.             [Route("UserInfo")]
  3.             public async Task<IHttpActionResult> SetUserInfo(UserViewModel model)
  4.             {
  5.                 if (!ModelState.IsValid)
  6.                 {
  7.                     return BadRequest(ModelState);
  8.                 }
  9.  
  10.                 var user = UserManager.FindByName(User.Identity.Name);
  11.  
  12.                 user.UserName = model.UserName;
  13.                 user.Email = model.Email;
  14.                 user.FullName = model.FullName;
  15.                 user.Skype = model.Skype;
  16.                 user.PhoneNumber = model.PhoneNumber;
  17.  
  18.                 SaverPhotos.SavePhoto(model);
  19.  
  20.                 IdentityResult result = await UserManager.UpdateAsync(user);
  21.  
  22.                 if (!result.Succeeded)
  23.                 {
  24.                     return GetErrorResult(result);
  25.                 }
  26.  
  27.                 return Ok();
  28.         }
  29.  
  30. public class UserViewModel
  31.     {
  32.         public string UserName { get; set; }
  33.         public string FullName { get; set; }
  34.         public string Email { get; set; }
  35.         public string Skype { get; set; }
  36.         public string PhoneNumber { get; set; }
  37.         public HttpPostedFileBase Avatar { get; set; }
  38.     }
  39.    
  40. $.ajax({
  41.                 type: 'PUT',
  42.                 contentType: false,
  43.                 processData: false,
  44.                 url: '/api/account/UserInfo',
  45.                 data: data,
  46.                 beforeSend: function (xhr) {
  47.                     var token = window.app.model.get('tokenInfo');
  48.                     xhr.setRequestHeader("Authorization", "Bearer " + token);
  49.                 },
  50.                 success: function (response) {
  51.                     alert("Successfully saving info!");
  52.                 },
  53.                 error: function (response) {
  54.                     alert('Error');
  55.                 }
  56.             });
  57.    
  58. <input type="file" name="Avatar" accept="image/png, image/jpeg, image/gif" id="profileAvatar"/>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top