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