コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: TgUsersRepository.cs プロジェクト: pacmad/Theatrel
        public async Task <bool> Delete(TelegramUserEntity userEntity)
        {
            _dbContext.TlUsers.Remove(userEntity);

            try
            {
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Trace.TraceError($"Failed to delete user item {ex.Message}");
                return(false);
            }
        }
コード例 #3
0
ファイル: TgUsersRepository.cs プロジェクト: pacmad/Theatrel
        public async Task <TelegramUserEntity> Create(long userId, string culture, CancellationToken cancellationToken)
        {
            var entity = new TelegramUserEntity {
                Id = userId, Culture = culture
            };

            try
            {
                _dbContext.TlUsers.Add(entity);
                await _dbContext.SaveChangesAsync(cancellationToken);

                return(entity);
            }
            catch (Exception ex)
            {
                Trace.TraceInformation($"DbException {ex.Message}");
                return(null);
            }
        }
コード例 #4
0
ファイル: TgUsersRepository.cs プロジェクト: pacmad/Theatrel
        public async Task <bool> Update(TelegramUserEntity newValue)
        {
            TelegramUserEntity oldValue = await GetById(newValue.Id);

            if (oldValue == null)
            {
                return(false);
            }

            _dbContext.Entry(newValue).State = EntityState.Modified;

            try
            {
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Trace.TraceError($"Failed to update chat item {ex.Message}");
                return(false);
            }
        }
コード例 #5
0
        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 });
        }