Esempio n. 1
0
        private ReasonOfChanges ComparePerformanceData(PlaybillChangeEntity lastChange, IPerformanceData freshData)
        {
            int freshMinPrice = freshData.MinPrice;

            if (lastChange == null)
            {
                return(freshMinPrice == 0 ? ReasonOfChanges.Creation : ReasonOfChanges.StartSales);
            }

            if (lastChange.MinPrice == 0)
            {
                return(freshMinPrice == 0 ? ReasonOfChanges.NoReason : ReasonOfChanges.StartSales);
            }

            if (lastChange.MinPrice > freshMinPrice)
            {
                return(ReasonOfChanges.PriceDecreased);
            }

            if (lastChange.MinPrice < freshMinPrice)
            {
                return(ReasonOfChanges.PriceIncreased);
            }

            return(ReasonOfChanges.NoReason);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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;
                }
            }
        }
Esempio n. 4
0
        private string GetChangeDescription(SubscriptionEntity subscription, PlaybillChangeEntity change)
        {
            var culture = CultureInfo.CreateSpecificCulture(subscription.TelegramUser.Culture);

            ReasonOfChanges reason = (ReasonOfChanges)change.ReasonOfChanges;

            switch (reason)
            {
            case ReasonOfChanges.Creation:
                string month = culture.DateTimeFormat.GetMonthName(change.PlaybillEntity.When.Month);
                return($"Новое в афише на {month}: {change.PlaybillEntity.Performance.Name} {change.PlaybillEntity.Url}");

            case ReasonOfChanges.PriceDecreased:
                return($"Снижена цена на {change.PlaybillEntity.Performance.Name} цена билета от {change.MinPrice} {change.PlaybillEntity.Url}");

            case ReasonOfChanges.PriceIncreased:
                return($"Билеты подорожали {change.PlaybillEntity.Performance.Name} цена билета от {change.MinPrice} {change.PlaybillEntity.Url}");

            case ReasonOfChanges.StartSales:
                return($"Появились в продаже билеты на {change.PlaybillEntity.Performance.Name} цена билета от {change.MinPrice} {change.PlaybillEntity.Url}");
            }

            return(null);
        }