/// <summary> /// Tạo Seat mới /// </summary> /// <param name="UserEntity"></param> /// <param name="SeatEntity"></param> /// <returns></returns> public SeatEntity Create(UserEntity UserEntity, SeatEntity SeatEntity) { using (var transaction = CinemasEntities.Database.BeginTransaction()) { try { Seat Seat = new Seat(); Seat = SeatEntity.ToModel(Seat); CinemasEntities.Seats.Add(Seat); CinemasEntities.SaveChanges(); SeatEntity.Id = Seat.Id; transaction.Commit(); return(SeatEntity); } catch (Exception ex) { transaction.Rollback(); throw new BadRequestException("Không tạo được Seat mới"); } } return(null); }
/// <summary> /// Cập nhật Seat theo Id /// </summary> /// <param name="UserEntity"></param> /// <param name="SeatId"></param> /// <param name="SeatEntity"></param> /// <returns></returns> public SeatEntity Update(UserEntity UserEntity, int SeatId, SeatEntity SeatEntity) { using (var transaction = CinemasEntities.Database.BeginTransaction()) { try { Seat Seat = CinemasEntities.Seats.Where(c => c.Id.Equals(SeatId)).FirstOrDefault(); if (Seat == null) { throw new BadRequestException("Không tìm thấy Seat có Id là " + SeatId); } Seat = SeatEntity.ToModel(Seat); CinemasEntities.SaveChanges(); transaction.Commit(); return(SeatEntity); } catch (Exception ex) { transaction.Rollback(); throw new BadRequestException("Không cập nhập được Seat"); } } }