コード例 #1
0
ファイル: RoomService.cs プロジェクト: hoangtamuet/Cinemas
 // 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");
         }
     }
 }
コード例 #2
0
ファイル: RoomService.cs プロジェクト: hoangtamuet/Cinemas
 // 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");
         }
     }
 }
コード例 #3
0
ファイル: RoomController.cs プロジェクト: hoangtamuet/Cinemas
 public RoomEntity Update([FromUri] int RoomId, [FromBody] RoomEntity RoomEntity)
 {
     return(RoomService.Update(UserEntity, RoomId, RoomEntity));
 }
コード例 #4
0
ファイル: RoomController.cs プロジェクト: hoangtamuet/Cinemas
 public RoomEntity Create([FromBody] RoomEntity RoomEntity)
 {
     return(RoomService.Create(UserEntity, RoomEntity));
 }