public async Task <IActionResult> PutSection(int id, Section section) { if (id != section.Id) { return(BadRequest()); } try { Section TempSection = _context.Sections.AsNoTracking().FirstOrDefault(x => x.Id == id); _context.Entry(section).State = EntityState.Modified; await _context.SaveChangesAsync(); if (TempSection.Title != section.Title) { var folderName = Path.Combine(_hostingEnvironment.WebRootPath, TempSection.Title); var folderNameNew = Path.Combine(_hostingEnvironment.WebRootPath, section.Title); if (Directory.Exists(folderName)) { Directory.Move(folderName, folderNameNew); } } } catch (Exception e) { if (!SectionExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] Article article) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != article.Id) { return(BadRequest()); } _context.Entry(article).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); unitOfWork.Save(); }
public IActionResult PutComputer([FromBody] Computer computer, int id) { if (computer.id != id) { return(BadRequest()); } db.Entry(computer).State = EntityState.Modified; db.SaveChanges(); return(Ok()); }