public async Task <HttpResponseMessage> SetAvatar(string userName) { var httpRequest = HttpContext.Current.Request; var postedFile = httpRequest.Files["Image"]; byte[] imageData; using (BinaryReader binaryReader = new BinaryReader(postedFile.InputStream)) imageData = binaryReader.ReadBytes(postedFile.ContentLength); var user = await _userService.FindByNameAsync(userName); var profile = await _clientProfileService.FindByIdAsync(user.ClientProfileId); await _clientProfileService.SetAvatarAsync(profile.Id, imageData); return(Request.CreateResponse(HttpStatusCode.Created)); }