public async Task <bool> UpdateArt(CreateArtData art) { Art newArt = new Art { ArtId = art.ArtId, ProfileId = art.ProfileId, Title = art.Title, Content = art.Content, Description = art.Description }; _context.Entry(newArt).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(true); } catch (DbUpdateConcurrencyException) { if (!ArtExists(art.ArtId)) { return(false); } else { throw new NotImplementedException(); } } }
public async Task <ActionResult <Art> > CreateArt(int profileId, CreateArtData art, IFormFile artFile) { if (profileId != art.ProfileId) { return(BadRequest()); } var newArt = await artRepository.CreateArt(art); return(CreatedAtAction("GetArt", new { profileId = newArt.ProfileId, artId = newArt.ArtId }, newArt)); }
public async Task <IActionResult> UpdateArt(int profileId, int artId, CreateArtData art) { // for update, delete current art, replace with new art if (artId != art.ArtId || profileId != art.ProfileId) { return(BadRequest()); } if (!await artRepository.UpdateArt(art)) { return(NotFound()); } return(NoContent()); }
public async Task <ArtDto> CreateArt(CreateArtData art) { Art newArt = new Art { ProfileId = art.ProfileId, Title = art.Title, Content = art.Content, UploadDate = DateTime.Now, Description = art.Description }; _context.Art.Add(newArt); await _context.SaveChangesAsync(); return(await GetArt(newArt.ArtId)); }