public async Task <IActionResult> PutProfileAttachments([FromRoute] int id, [FromBody] ProfileAttachment profileAttachments) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != profileAttachments.ProfAttId) { return(BadRequest()); } _context.Entry(profileAttachments).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProfileAttachmentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
//Service To change Profile Picture. public async Task Upload(ProfilePicture input) { long size = 0; foreach (var file in input.F) { var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var c = "/images/" + filename; filename = _hostingEnv.WebRootPath + $@"\images\{filename}"; size += file.Length; /* var db = new ProfilePicture(); * db.ImagePath = c; * db.ProfileId = (long)AbpSession.UserId; */ ProfileAttachment update = _profileAttachment.FirstOrDefault(cc => cc.ProfileId == input.ProfileId); update.ImagePath = c; update.ProfileId = 10008; using (var stream = new FileStream(filename, FileMode.Create)) { await file.CopyToAsync(stream); await _profileAttachment.UpdateAsync(update); } } }
public async Task <IActionResult> PostProfileAttachments([FromBody] ProfileAttachment profileAttachments) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.ProfileAttachments.Add(profileAttachments); await _context.SaveChangesAsync(); return(CreatedAtAction("GetProfileAttachments", new { id = profileAttachments.ProfAttId }, profileAttachments)); }