public async Task <IActionResult> ChangeAvatar([FromForm] ChangeAvatarRequest request) { var response = await mediator.Send(request); logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} changed avatar", response.Error); return(response.IsSucceeded ? (IActionResult)Ok(response) : BadRequest(response)); }
public ActionResult ChangeAvatar([FromForm] ChangeAvatarRequest model) { try { string ext = Path.GetExtension(model.FormFile.FileName); string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/profile-pics", model.id + ext); using (Stream stream = new FileStream(path, FileMode.Create)){ model.FormFile.CopyTo(stream); } var response = _UserService.ChangeAvatar(model.id, model.id + ext); if (response == null) { return(BadRequest("Something went wrong")); } return(Ok(response)); }catch { return(BadRequest("Something went wrong")); } }