public async Task <IActionResult> PutPlant([FromRoute] decimal id, [FromBody] Plant plant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != plant.Id) { return(BadRequest()); } _context.Entry(plant).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlantExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutChatroom([FromRoute] string id, [FromBody] Chatroom chatroom) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != chatroom.UserChat) { return(BadRequest()); } _context.Entry(chatroom).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChatroomExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutResponsible([FromRoute] decimal id, [FromBody] Responsible responsible) { IList <String> role = await GetUsersRoles(); if (role.Contains("Admin")) { using (var transaction = _context.Database.BeginTransaction()) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != responsible.RegistrationNumber) { return(BadRequest()); } _context.Entry(responsible).State = EntityState.Modified; try { await _context.SaveChangesAsync(); transaction.Commit(); } catch (DbUpdateConcurrencyException) { if (!ResponsibleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); } } return(Unauthorized()); }