public async Task EditRoomAsync(EditRoomModel editRoomModel) { var room = await Context.Room.FindAsync(editRoomModel.Id); room.RoomNumber = editRoomModel.RoomNumber; room.Capacity = editRoomModel.Capacity; await Context.SaveChangesAsync(); }
public IActionResult Put(uint id, [FromBody] EditRoomModel model) { if (ModelState.IsValid) { var room = _roomService.GetRoomById(id); if (room is null) { return(NotFound()); } room.Name = model.Name; return(Ok(_roomService.Update(room))); } return(BadRequest()); }
public async Task <IActionResult> Edit(long id, [FromBody] EditRoomModel model) { try { if (null == model || false == ModelState.IsValid) { return(BadRequest("Invalid State")); } await mediator.Send(new EditRoomCommand(id, model.Name, model.Description)); return(Ok()); } catch (Exception exception) { return(BadRequest(exception.Message)); } }
public async Task <IActionResult> Edit(EditRoomModel editRoom) { var errorMessage = String.Empty; if (!editRoom.ValidateEditModel(out errorMessage)) { ModelState.AddModelError(string.Empty, errorMessage); } else if (!RoomService.ValidateRoom(editRoom.MovieTheater, editRoom.RoomNumber, out errorMessage)) { ModelState.AddModelError(string.Empty, errorMessage); } else { await RoomService.EditRoomAsync(editRoom); return(RedirectToAction(nameof(Index))); } return(View()); }
public IActionResult EditRoom([FromBody] EditRoomModel data) { if (data == null) { return(BadRequest("Neivesti duomenys")); } if (data.Number < 0) { return(BadRequest("Blogas nr")); } if (data.Area < 0) { return(BadRequest("Blogas plotas")); } if (!new List <int>() { 1, 2, 3 }.Contains(data.TypeId)) // shouldn't be hardcoded xD { return(BadRequest("Blogas tipo id")); } if (data.Size < 0) { return(BadRequest("Nenurodytas vietu sk")); } if (string.IsNullOrEmpty(data.Address)) { return(BadRequest("Nenurodytas adresas")); } try { Db.Connection.Open(); var cmd = Db.Connection.CreateCommand() as MySqlCommand; cmd.CommandText = string.Format("UPDATE patalpos SET nr = {0}, plotas = {1}, vietu_sk = {2}, tipas = {3} WHERE nr = {4}", data.Number, data.Area, data.Size, data.TypeId, data.Number); cmd.ExecuteNonQuery(); Db.Connection.Close(); if (data.TypeId == 1) // palatos { Db.Connection.Open(); cmd.CommandText = string.Format(@"SELECT * FROM patalpos_uzimtumas WHERE patalpa_id = {0}", data.Number); var reader2 = cmd.ExecuteReader(); List <RoomAvailabilityModel> rooms = new List <RoomAvailabilityModel>(); while (reader2.Read()) { rooms.Add(new RoomAvailabilityModel() { roomId = Convert.ToInt32(reader2["patalpa_id"]), personCode = Convert.ToInt32(reader2["pacientas_asmensk"]) }); } Db.Connection.Close(); foreach (var room in rooms) { if (!data.Patients.Contains(room.personCode.ToString())) { Db.Connection.Open(); cmd.CommandText = string.Format("DELETE FROM patalpos_uzimtumas WHERE pacientas_asmensk = {0} AND patalpa_id = {1}", room.personCode, data.Number); cmd.ExecuteNonQuery(); } } } else if (data.TypeId == 2) // kabinetai { Db.Connection.Open(); cmd.CommandText = string.Format("UPDATE personalo_darbuotojai SET fk_PATALPAnr = {0} WHERE fk_PATALPAnr = {1}", null, data.Number); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format("UPDATE personalo_darbuotojai SET fk_PATALPAnr = {0} WHERE tabelio_numeris = {1}", data.Number, data.Doctor); cmd.ExecuteNonQuery(); Db.Connection.Close(); } else // laboratorijos { Db.Connection.Open(); cmd.CommandText = string.Format(@"SELECT * FROM proceduros_tipas WHERE name LIKE '%{0}%'", data.Procedure); var reader = cmd.ExecuteReader(); if (reader.Read()) { Db.Connection.Close(); string ids = Convert.ToString(reader["patalpa_id"]); int procedureId = Convert.ToInt32(reader["id"]); if (string.IsNullOrEmpty(data.Procedure)) { Db.Connection.Open(); ids.Replace(data.Number.ToString() + ";", ""); cmd.CommandText = string.Format("UPDATE proceduros_tipas SET patalpa_id = {0} WHERE id = {1}", ids, procedureId); cmd.ExecuteNonQuery(); Db.Connection.Close(); } else if (!ids.Contains(data.Number.ToString())) { Db.Connection.Open(); ids.Concat(data.Number.ToString() + ";"); cmd.CommandText = string.Format("UPDATE proceduros_tipas SET patalpa_id = {0} WHERE id = {1}", ids, procedureId); cmd.ExecuteNonQuery(); Db.Connection.Close(); } } else { return(StatusCode(500, "Patalpos redaguoti nepavyko patikrinkite duomenis.")); } } return(Ok()); } catch (Exception e) { return(StatusCode(500, "Patalpos redaguoti nepavyko patikrinkite duomenis.")); } }