public void Save(IMediaSource replaceAutoPadding, IUser currentUser) { ValidatePlayItems(); if (_entity == null) { _entity = new PlaybillEntity(); } var playItemEntities = ToEntities(_entity, this.PlayItemCollection, replaceAutoPadding); _entity.StartTime = playItemEntities[0].StartTime; _entity.Duration = playItemEntities[playItemEntities.Count - 1].StopTime.Subtract(_entity.StartTime).TotalSeconds; var oldId = _entity.Id; var oldEditorId = _entity.LastEditorId; try { PlayoutRepository.SavePlaybill(_entity, playItemEntities, currentUser); } catch (Exception ex) { _entity.Id = oldId; _entity.LastEditorId = oldEditorId; throw; } }
//public PlayItemEntity ToEntity(PlaybillEntity billEntity, IPlayItem playItem) //{ // var dtoItem = new PlayItemEntity(); // dtoItem.Id = playItem.Id; // dtoItem.StartTime = playItem.StartTime; // dtoItem.PlayDuration = playItem.CalculatedPlayDuration.TotalSeconds; // dtoItem.MarkerIn = playItem.PlayRange.StartPosition.TotalSeconds; // dtoItem.MarkerDuration = playItem.PlayRange.Duration.TotalSeconds; // dtoItem.PlaybillItem = ToEntity(billEntity, playItem.PlaybillItem); // return dtoItem; //} //public PlaybillItemEntity ToEntity(PlaybillEntity billEntity, IPlaybillItem billItem) //{ // var dtoItem = new PlaybillItemEntity(); // dtoItem.Id = billItem.Id; // dtoItem.Playbill = billEntity; // dtoItem.StartTime = billItem.StartTime; // dtoItem.MarkerIn = billItem.PlayRange.StartPosition.TotalSeconds; // dtoItem.ScheduleMode = billItem.ScheduleMode; // dtoItem.MarkerDuration = billItem.PlayRange.Duration.TotalSeconds; // if (billItem.MediaSource.Category!=MediaSourceCategory.Null) // { // dtoItem.MediaSourceId = billItem.MediaSource.Id; // } // else // { // dtoItem.MediaSourceTitle = billItem.MediaSource.Title; // dtoItem.MediaSourceDuration = billItem.MediaSource.Duration.Value.TotalSeconds; // } // var autoBillItem = billItem as AutoPlaybillItem; // if (autoBillItem != null) // { // dtoItem.IsAutoPadding = autoBillItem.IsAutoPadding; // } // var fileMediaSource = billItem.MediaSource as IFileMediaSource; // if (fileMediaSource != null) // { // dtoItem.AudioGain = fileMediaSource.AudioGain; // } // if (billItem.CGItems != null) // { // dtoItem.CGContents = CGItemCollection.ToXml(billItem.CGItems); // } // return dtoItem; //} public static Playbill Load(Guid id, IList <IPlayItem> playItemList) { PlaybillEntity billEntity = PlayoutRepository.GetPlaybill(id); // GetEntity(id); Playbill playbill = null; Dictionary <Guid, IPlaybillItem> playbillItemDict = new Dictionary <Guid, IPlaybillItem>(); if (billEntity != null) { playbill = new Playbill(billEntity); for (int i = 0; i < billEntity.PlayItems.Count; i++) { PlayItemEntity playItemEntity = billEntity.PlayItems[i]; IPlaybillItem playbillItem = null; if (!playbillItemDict.ContainsKey(playItemEntity.PlaybillItemId)) { playbillItem = playItemEntity.PlaybillItem.ToPlaybillItem(); // FromEntity(playItemEntity.PlaybillItem); playbillItemDict.Add(playItemEntity.PlaybillItemId, playbillItem); } else { playbillItem = playbillItemDict[playItemEntity.PlaybillItemId]; } IPlayItem playItem = playItemEntity.ToPlayItem(playbillItem); // FromEntity(playItemEntity,playbillItem); playItemList.Add(playItem); } } return(playbill); }
public async Task <bool> AddChange(PlaybillEntity entity, PlaybillChangeEntity change) { PlaybillEntity oldValue = await GetById(entity.Id); if (oldValue == null) { return(false); } entity.Changes.Add(change); _dbContext.Add(change); _dbContext.Entry(entity).State = EntityState.Modified; try { await _dbContext.SaveChangesAsync(); return(true); } catch (Exception ex) { Trace.TraceInformation($"AddChange DbException {ex.Message} InnerException {ex.InnerException?.Message}"); return(false); } }
private void ConfigureDb(AppDbContext dbContext, params int[] months) { var tgUser1 = new TelegramUserEntity { Culture = "ru" }; var tgUser2 = new TelegramUserEntity { Culture = "ru" }; dbContext.TlUsers.Add(tgUser1); dbContext.TlUsers.Add(tgUser2); var playBillEntryWithDecreasedPrice = new PlaybillEntity { Performance = new PerformanceEntity { Name = "TestBallet", Location = new LocationsEntity("Room2"), Type = new PerformanceTypeEntity("Ballet") }, Url = "TestUrl", When = new DateTime(2020, months.First(), 1), }; dbContext.Playbill.Add(playBillEntryWithDecreasedPrice); //subscription for tgUser1 for particular performance dbContext.Subscriptions.Add(new SubscriptionEntity { TelegramUserId = tgUser1.Id, LastUpdate = DateTime.Now, PerformanceFilter = new PerformanceFilterEntity { PerformanceId = playBillEntryWithDecreasedPrice.PerformanceId }, TrackingChanges = (int)(ReasonOfChanges.PriceDecreased | ReasonOfChanges.StartSales) }); foreach (var month in months.Skip(1)) { DateTime startDate = new DateTime(2020, month, 1); DateTime endDateTime = startDate.AddMonths(1).AddDays(-1); //subscription user2 for filter by date dbContext.Subscriptions.Add(new SubscriptionEntity { TelegramUserId = tgUser2.Id, LastUpdate = DateTime.Now, PerformanceFilter = new PerformanceFilterEntity { StartDate = startDate, EndDate = endDateTime }, TrackingChanges = (int)(ReasonOfChanges.PriceDecreased | ReasonOfChanges.StartSales) }); } dbContext.SaveChanges(); }
public async Task <bool> Update(PlaybillChangeEntity entity) { PlaybillChangeEntity oldValue = await GetChangeById(entity.Id); if (oldValue == null) { return(false); } PlaybillEntity playbillEntity = null; try { playbillEntity = _dbContext.Playbill .Include(p => p.Performance) .ThenInclude(p => p.Type) .Include(p => p.Performance) .ThenInclude(p => p.Location) .Include(p => p.Changes) .FirstOrDefault(p => p.Id == entity.PlaybillEntityId); var updatedChange = playbillEntity?.Changes.FirstOrDefault(ch => ch.Id == entity.Id); if (updatedChange == null) { return(false); } updatedChange.LastUpdate = entity.LastUpdate; await _dbContext.SaveChangesAsync(); return(true); } catch (Exception ex) { Trace.TraceInformation( $"Update Change entity DbException {ex.Message} InnerException {ex.InnerException?.Message}"); return(false); } finally { if (playbillEntity != null) { _dbContext.Entry(playbillEntity.Performance.Location).State = EntityState.Detached; _dbContext.Entry(playbillEntity.Performance.Type).State = EntityState.Detached; _dbContext.Entry(playbillEntity.Performance).State = EntityState.Detached; foreach (var change in playbillEntity.Changes) { _dbContext.Entry(change).State = EntityState.Detached; } _dbContext.Entry(playbillEntity).State = EntityState.Detached; } } }
public static PlaybillItemEntity ToEntity(PlaybillEntity billEntity, IPlaybillItem billItem, IMediaSource replaceAutoPadding) { var dtoItem = new PlaybillItemEntity(); dtoItem.Id = billItem.Id; dtoItem.Playbill = billEntity; dtoItem.StartTime = billItem.StartTime; dtoItem.MarkerIn = billItem.PlayRange.StartPosition.TotalSeconds; dtoItem.ScheduleMode = billItem.ScheduleMode; dtoItem.MarkerDuration = billItem.PlayRange.Duration.TotalSeconds; //_dtoItem.SegmentId = this.SegmentId; if (billItem.MediaSource.Category != MediaSourceCategory.Null) { dtoItem.MediaSourceId = billItem.MediaSource.Id; } else { dtoItem.MediaSourceTitle = billItem.MediaSource.Title; dtoItem.MediaSourceDuration = billItem.MediaSource.Duration.Value.TotalSeconds; } var autoBillItem = billItem as AutoPlaybillItem; if (autoBillItem != null) { if (autoBillItem.IsAutoPadding && replaceAutoPadding != null) { // TODO: 替换自动垫片。 dtoItem.MediaSourceId = replaceAutoPadding.Id; //dtoItem.IsAutoPadding = autoBillItem.IsAutoPadding; } } var fileMediaSource = billItem.MediaSource as IFileMediaSource; if (fileMediaSource != null) { dtoItem.AudioGain = fileMediaSource.AudioGain; } if (billItem.CGItems != null) { dtoItem.CGContents = CGItemCollection.ToXml(billItem.CGItems); } return(dtoItem); }
private IList <PlayItemEntity> ToEntities(PlaybillEntity billEntity, IPlayItemCollection playItemCollection, IMediaSource replaceAutoPadding) { List <PlayItemEntity> result = new List <PlayItemEntity>(); for (int i = 0; i < playItemCollection.Count; i++) { result.Add(playItemCollection[i].ToEntity(billEntity, replaceAutoPadding)); //result.Add(ToEntity(billEntity, playItemCollection[i])); } return(result); }
public static PlayItemEntity ToEntity(this IPlayItem playItem, PlaybillEntity billEntity, IMediaSource replaceAutoPadding) { var dtoItem = new PlayItemEntity(); dtoItem.Id = playItem.Id; dtoItem.StartTime = playItem.StartTime; dtoItem.PlayDuration = playItem.CalculatedPlayDuration.TotalSeconds; dtoItem.MarkerIn = playItem.PlayRange.StartPosition.TotalSeconds; dtoItem.MarkerDuration = playItem.PlayRange.Duration.TotalSeconds; dtoItem.PlaybillItem = ToEntity(billEntity, playItem.PlaybillItem, replaceAutoPadding); //.ToEntity(); return(dtoItem); }
public async Task <PlaybillEntity> AddPlaybill(IPerformanceData data) { try { int performanceId = GetPerformanceEntityId(data, out int location, out int type); PerformanceEntity performance = -1 == performanceId ? AddPerformanceEntity(data, location, type) : _dbContext.Performances .Include(p => p.Location) .Include(p => p.Type) .FirstOrDefault(p => p.Id == performanceId); var playBillEntry = new PlaybillEntity { Performance = performance, Url = data.Url, When = data.DateTime, Changes = new List <PlaybillChangeEntity> { new PlaybillChangeEntity { LastUpdate = DateTime.Now, MinPrice = data.MinPrice, ReasonOfChanges = (int)ReasonOfChanges.Creation, } } }; _dbContext.Playbill.Add(playBillEntry); _dbContext.Add(playBillEntry.Changes.First()); await _dbContext.SaveChangesAsync(); if (performance != null) { _dbContext.Entry(performance.Location).State = EntityState.Detached; _dbContext.Entry(performance.Type).State = EntityState.Detached; _dbContext.Entry(performance).State = EntityState.Detached; } return(playBillEntry); } catch (Exception ex) { Trace.TraceInformation($"AddPlaybill DbException {ex.Message} InnerException {ex.InnerException?.Message}"); } return(null); }
private async Task <int> ConfigureDb(AppDbContext dbContext, string url, DateTime performanceDateTime) { DateTime dt1 = performanceDateTime.AddDays(-3); DateTime dt2 = performanceDateTime.AddDays(-2); var playbillEntryWithDecreasedPrice = new PlaybillEntity { Performance = new PerformanceEntity { Name = "TestOpera", Location = new LocationsEntity { Name = "TestLocation" }, Type = new PerformanceTypeEntity { TypeName = "Opera" } }, When = performanceDateTime, Url = url, Changes = new List <PlaybillChangeEntity> { new PlaybillChangeEntity { LastUpdate = dt1, MinPrice = 800, ReasonOfChanges = (int)ReasonOfChanges.StartSales, }, new PlaybillChangeEntity { LastUpdate = dt2, MinPrice = 500, ReasonOfChanges = (int)ReasonOfChanges.PriceDecreased, } } }; dbContext.Playbill.Add(playbillEntryWithDecreasedPrice); await dbContext.SaveChangesAsync(); return(playbillEntryWithDecreasedPrice.Id); }
private async Task <long[]> ConfigureDb(AppDbContext dbContext) { DateTime dt1 = DateTime.Now.AddDays(-3); DateTime dt2 = DateTime.Now.AddDays(-2); DateTime dt3 = DateTime.Now.AddDays(-1); DateTime performanceDateTime = DateTime.Now.AddDays(10); var tgUser1 = new TelegramUserEntity { Culture = "ru" }; var tgUser2 = new TelegramUserEntity { Culture = "ru" }; var tgUser3 = new TelegramUserEntity { Culture = "ru" }; dbContext.TlUsers.Add(tgUser1); dbContext.TlUsers.Add(tgUser2); var playbillEntryWithDecreasedPrice = new PlaybillEntity() { Performance = new PerformanceEntity() { Name = "TestOpera", Location = new LocationsEntity("TestLocation"), Type = new PerformanceTypeEntity("Opera") }, When = performanceDateTime, Changes = new List <PlaybillChangeEntity>(new[] { new PlaybillChangeEntity { LastUpdate = dt1, MinPrice = 700, ReasonOfChanges = (int)ReasonOfChanges.Creation, }, new PlaybillChangeEntity { LastUpdate = dt3, MinPrice = 500, ReasonOfChanges = (int)ReasonOfChanges.PriceDecreased, } }) }; dbContext.Playbill.Add(playbillEntryWithDecreasedPrice); //subscription for tgUser1 for particular performance dbContext.Subscriptions.Add(new SubscriptionEntity { TelegramUserId = tgUser1.Id, LastUpdate = dt2, PerformanceFilter = new PerformanceFilterEntity { PerformanceId = playbillEntryWithDecreasedPrice.PerformanceId }, TrackingChanges = (int)(ReasonOfChanges.PriceDecreased | ReasonOfChanges.StartSales) }); //subscription user2 for filter by date dbContext.Subscriptions.Add(new SubscriptionEntity { TelegramUserId = tgUser2.Id, LastUpdate = dt2, PerformanceFilter = new PerformanceFilterEntity { StartDate = performanceDateTime.AddDays(-1), EndDate = performanceDateTime.AddDays(2) }, TrackingChanges = (int)(ReasonOfChanges.PriceDecreased | ReasonOfChanges.StartSales) }); //subscription for user2 for particular performance with events price increased and start sales dbContext.Subscriptions.Add(new SubscriptionEntity { TelegramUserId = tgUser3.Id, LastUpdate = dt2, PerformanceFilter = new PerformanceFilterEntity { PerformanceId = playbillEntryWithDecreasedPrice.PerformanceId }, TrackingChanges = (int)(ReasonOfChanges.PriceIncreased | ReasonOfChanges.StartSales) }); await dbContext.SaveChangesAsync(); return(new[] { tgUser1.Id, tgUser2.Id }); }
public BindablePlaybill(PlaybillEntity entity) { this._entity = entity; }
private Playbill(PlaybillEntity billEntity) { _entity = billEntity; }