public async Task <IActionResult> PutType(long id, Type type) { if (id != type.IdType) { return(BadRequest()); } _context.Entry(type).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Type> > PostType(Type type) { var types = await _context.Types.ToListAsync(); var typeExist = await _context.Types.AnyAsync(x => x.Name == type.Name); if (typeExist != false) { return(types.Where(x => x.Name == type.Name).First()); } _context.Types.Add(type); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetType), new { id = type.IdType }, type)); }