// Tạo Room mới public RoomEntity Create(UserEntity UserEntity, RoomEntity RoomEntity) { using (var transaction = CinemasEntities.Database.BeginTransaction()) { try { Room Room = new Room(); Room = RoomEntity.ToModel(Room); CinemasEntities.Rooms.Add(Room); CinemasEntities.SaveChanges(); RoomEntity.Id = Room.Id; transaction.Commit(); return(RoomEntity); } catch (Exception ex) { transaction.Rollback(); throw new BadRequestException("Không tạo được Room mới"); } } }
// Cập nhật Room theo Id public RoomEntity Update(UserEntity UserEntity, int RoomId, RoomEntity RoomEntity) { using (var transaction = CinemasEntities.Database.BeginTransaction()) { try { Room Room = CinemasEntities.Rooms.Where(c => c.Id.Equals(RoomId)).FirstOrDefault(); if (Room == null) { throw new BadRequestException("Không tìm thấy Room có Id là " + RoomId); } Room = RoomEntity.ToModel(Room); CinemasEntities.SaveChanges(); transaction.Commit(); return(RoomEntity); } catch (Exception ex) { transaction.Rollback(); throw new BadRequestException("Không cập nhập được Room"); } } }
public RoomEntity Update([FromUri] int RoomId, [FromBody] RoomEntity RoomEntity) { return(RoomService.Update(UserEntity, RoomId, RoomEntity)); }
public RoomEntity Create([FromBody] RoomEntity RoomEntity) { return(RoomService.Create(UserEntity, RoomEntity)); }