Ejemplo n.º 1
0
        private async Task ManageTMEF()
        {
            this.Update.UserContext.RemoveContext("EntryFee_Id");

            var commandParts = this.Update.Command.Split(' ');

            if (commandParts.Length > 1 && Guid.TryParse(commandParts[1], out var efId))
            {
                await this.ManageTMEF(efId);

                return;
            }

            var tmhId = this.Update.UserContext.GetContext <Guid?>("TMHId");
            var tmvId = this.Update.UserContext.GetContext <Guid?>("TMVId");

            var operationType = tmhId == default ? tmvId == default ?
                                FeeOperationEnum.UnknownFee : FeeOperationEnum.VisitorEntryFee : FeeOperationEnum.HosterEntryFee;

            if (operationType == FeeOperationEnum.UnknownFee)
            {
                throw new ArgumentException();
            }

            if (!tmvId.HasValue && !tmhId.HasValue)
            {
                return;
            }

            IQueryable <TurnipMarketEntryFee> efs = this.Context.TurnipMarketEntryFees
                                                    .Where(ef => ef.TurnipMarketHosterId == tmhId ||
                                                           ef.TurnipMarketVisitorId == tmvId);

            var keyboard = new List <Tuple <string, string>[]>();

            foreach (var ef in efs)
            {
                keyboard.Add(new Tuple <string, string>[]
                {
                    new Tuple <string, string>(
                        $"/ManageTMEF {ef.Id}",
                        $"{ef.FeeType.GetDescription()} {ef.Count}"),
                });
            }

            keyboard.Add(new Tuple <string, string>[] { new Tuple <string, string>($"/CreateTMEF", "Create entry fee") });

            keyboard.Add(new Tuple <string, string>[]
            {
                new Tuple <string, string>(
                    (operationType == FeeOperationEnum.HosterEntryFee) ? $"/BackToHoster" : $"/BackToVisitor",
                    "<- Back"),
            });

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                $"Change entry fee for {operationType.GetDescription()}:",
                CommandHelper.BuildKeyboard(keyboard.ToArray()));
        }
Ejemplo n.º 2
0
        private async Task ManageTMH(Guid id)
        {
            var tmh = await this.Context.TurnipMarketHosters
                      .Include(tmh => tmh.EntryFees)
                      .FirstOrDefaultAsync(tmh => tmh.Id == id);

            if (tmh == null)
            {
                await this.ManageTMH();

                return;
            }

            var sb = new StringBuilder();

            sb.AppendLine($"Available from - {DateTimeConverter.ToUserDate(tmh.BeginingDate, this.Update.UserContext.Timezone)}");
            sb.AppendLine($"Expires - {DateTimeConverter.ToUserDate(tmh.ExpirationDate, this.Update.UserContext.Timezone)}");
            sb.AppendLine($"Turnip price - {tmh.Price}");
            sb.AppendLine($"Description - {tmh.Description}");
            sb.AppendLine($"Entry fee:");
            foreach (var fee in tmh.EntryFees)
            {
                sb.AppendLine($"\t\t{fee.FeeType.GetDescription()} {fee.Count} ({fee.Description})");
            }

            sb.AppendLine($"\nWhat do you wish to change?");

            this.Update.UserContext.SetContext("TMHId", id);

            var keyboard = new List <Tuple <string, string>[]>()
            {
                new[]
                {
                    new Tuple <string, string>("/ChangeDate", "Change market date"),
                    new Tuple <string, string>("/ChangePrice", "Change turnip price"),
                },
                new[]
                {
                    new Tuple <string, string>("/ChangeDescription", "Change description"),
                    new Tuple <string, string>("/ChangeEntryFee", "Change entry fee"),
                },
                new[]
                {
                    new Tuple <string, string>($"/DeleteTMH", "Delete market record"),
                    new Tuple <string, string>("/BackManageTMH", "<- Back"),
                },
            };

            if (tmh.BeginingDate <= DateTime.Now)
            {
                keyboard.Add(new[] { new Tuple <string, string>($"/FindVisitor {tmh.Id}", "Find visitors") });
            }

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                sb.ToString(),
                CommandHelper.BuildKeyboard(keyboard.ToArray()));
        }
        private async Task <bool> FindHoster()
        {
            int skip = default;

            var commandParts = this.Update.Command.Split(' ', StringSplitOptions.RemoveEmptyEntries);

            if (commandParts.Count() > 2)
            {
                int.TryParse(commandParts[2], out skip);
            }

            var visitorId = this.Update.UserContext.GetContext <Guid>("TMVId");

            var tmv = await this.Context.TurnipMarketVisitors.FindAsync(visitorId);

            var tmh = this.Context.TurnipMarketHosters
                      .Include(tmh => tmh.User)
                      .Where(tmh => tmh.User.LastActiveDate > DateTime.Now.AddHours(-2) &&
                             tmh.BeginingDate <DateTime.Now &&
                                               tmh.ExpirationDate> DateTime.Now &&
                             tmh.Price > tmv.PriceLowerBound &&
                             tmh.UserId != this.Update.UserContext.UserId)
                      .OrderByDescending(tmh => tmh.Price)
                      .Skip(skip)
                      .Take(10);

            var keyboard = tmh
                           .Select(tmh => new[]
            {
                new Tuple <string, string>(
                    $"/HosterDescription {tmh.Id}",
                    $"{DateTimeConverter.ToUserDate(tmh.ExpirationDate, this.Update.UserContext.Timezone):dd.MM.yyyy HH} - {tmh.Price}"),
            }).ToList();

            if (keyboard.Count >= 10)
            {
                keyboard.Add(new[] { new Tuple <string, string>($"/FindHoster {skip + 10}", "Next page >>") });
            }

            if (skip > 0)
            {
                keyboard.Add(new[] { new Tuple <string, string>($"/FindHoster {skip - 10}", "<< Previous page") });
            }

            keyboard.Add(new[] { new Tuple <string, string>("/BackToVisitor", "<- Back") });

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                "Here is a list of currently available hosters for your visitor application:",
                CommandHelper.BuildKeyboard(keyboard.ToArray()));

            return(false);
        }
        private async Task <bool> FindVisitor()
        {
            int skip = default;

            var commandParts = this.Update.Command.Split(' ', StringSplitOptions.RemoveEmptyEntries);

            if (commandParts.Count() > 2)
            {
                int.TryParse(commandParts[2], out skip);
            }

            var hosterId = this.Update.UserContext.GetContext <Guid>("TMHId");

            var tmh = await this.Context.TurnipMarketHosters.FindAsync(hosterId);

            var tmv = this.Context.TurnipMarketVisitors
                      .Include(tmv => tmv.User)
                      .Where(tmv => tmv.User.LastActiveDate > DateTime.Now.AddHours(-2) &&
                             tmv.PriceLowerBound < tmh.Price &&
                             tmv.UserId != this.Update.UserContext.UserId)
                      .OrderBy(tmv => tmv.PriceLowerBound)
                      .Skip(skip)
                      .Take(10);

            var keyboard = tmv
                           .Select(tmv => new[]
            {
                new Tuple <string, string>(
                    $"/VisitorDescription {tmv.Id}",
                    $"Wanted price - {tmv.PriceLowerBound}"),
            }).ToList();

            if (keyboard.Count >= 10)
            {
                keyboard.Add(new[] { new Tuple <string, string>($"/FindVisitor {skip + 10}", "Next page >>") });
            }

            if (skip > 0)
            {
                keyboard.Add(new[] { new Tuple <string, string>($"/FindVisitor {skip - 10}", "<< Previous page") });
            }

            keyboard.Add(new[] { new Tuple <string, string>("/BackToHoster", "<- Back") });

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                "Here is a list of currently available visitor for your hosted market:",
                CommandHelper.BuildKeyboard(keyboard.ToArray()));

            return(false);
        }
        private async Task <bool> ViewHosterDescription()
        {
            var commandParts = this.Update.Command.Split(' ');

            if (commandParts.Count() < 2 || !Guid.TryParse(commandParts[1], out var hosterId))
            {
                return(true);
            }

            var id = this.Update.UserContext.GetContext <Guid>("TMVId");

            var tmh = await this.Context.TurnipMarketHosters
                      .Include(tmh => tmh.User)
                      .Include(tmh => tmh.User.UserContacts)
                      .Include(tmh => tmh.EntryFees)
                      .FirstOrDefaultAsync(tmh => tmh.Id == hosterId);

            var sb = new StringBuilder();

            sb.AppendLine(this.GetUserInfo(tmh.User));
            sb.AppendLine($"Available from - {DateTimeConverter.ToUserDate(tmh.BeginingDate, this.Update.UserContext.Timezone)}");
            sb.AppendLine($"Expires - {DateTimeConverter.ToUserDate(tmh.ExpirationDate, this.Update.UserContext.Timezone)}");
            sb.AppendLine($"Turnip price - {tmh.Price}");
            sb.AppendLine($"Description - {tmh.Description}");
            sb.AppendLine($"Entry fee:");
            foreach (var fee in tmh.EntryFees)
            {
                sb.AppendLine($"\t\t{fee.FeeType.GetDescription()} {fee.Count} ({fee.Description})");
            }

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                sb.ToString(),
                CommandHelper.BuildKeyboard(
                    new[]
            {
                new[] { new Tuple <string, string>($"/ReportHoster {hosterId}", "Report hosted market") },
                new[] { new Tuple <string, string>($"/FindHoster {id}", "<- Back") },
            }));

            return(false);
        }
        private async Task <bool> ViewVisitorDescription()
        {
            var commandParts = this.Update.Command.Split(' ');

            if (commandParts.Count() < 2 || !Guid.TryParse(commandParts[1], out var visitorId))
            {
                return(true);
            }

            var id = this.Update.UserContext.GetContext <Guid>("TMHId");

            var tmv = await this.Context.TurnipMarketVisitors
                      .Include(tmv => tmv.User)
                      .Include(tmh => tmh.User.UserContacts)
                      .Include(tmh => tmh.EntryFees)
                      .FirstOrDefaultAsync(tmv => tmv.Id == visitorId);

            var sb = new StringBuilder();

            sb.AppendLine(this.GetUserInfo(tmv.User));
            sb.AppendLine($"Description - {tmv.Description}");
            sb.AppendLine($"Price lower bound - {tmv.PriceLowerBound}");
            sb.AppendLine($"Entry fee:");
            foreach (var fee in tmv.EntryFees)
            {
                sb.AppendLine($"\t\t{fee.FeeType.GetDescription()} {fee.Count} ({fee.Description})");
            }

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                sb.ToString(),
                CommandHelper.BuildKeyboard(
                    new[]
            {
                new[] { new Tuple <string, string>($"/ReportVisitor {visitorId}", "Report visitor application") },
                new[] { new Tuple <string, string>($"/FindVisitor {id}", "<- Back") },
            }));

            return(false);
        }
Ejemplo n.º 7
0
        private async Task ManageTMEF(Guid efId)
        {
            var ef = await this.Context.TurnipMarketEntryFees.FindAsync(efId);

            if (ef == null)
            {
                throw new ArgumentException();
            }

            this.Update.UserContext.SetContext("EntryFee_Id", efId);

            var keyboard = new Tuple <string, string>[][]
            {
                new Tuple <string, string>[]
                {
                    new Tuple <string, string>($"/ChangeType", "Change type"),
                    new Tuple <string, string>($"/ChangeCount", "Change count"),
                },
                new Tuple <string, string>[]
                {
                    new Tuple <string, string>($"/ChangeDescription", "Change description"),
                    new Tuple <string, string>($"/DeleteEF", "Delete record"),
                },
                new Tuple <string, string>[] { new Tuple <string, string>($"/ManageTMEF", "<- Back") },
            };

            var sb = new StringBuilder();

            sb.AppendLine($"Type - {ef.FeeType.GetDescription()}");
            sb.AppendLine($"Count - {ef.Count}");
            sb.AppendLine($"Description - {ef.Description}");
            sb.AppendLine($"\nWhat do you want to change:");

            await this.Client.EditMessageAsync(
                this.Update.UserContext.TelegramId,
                this.Update.MessageId,
                sb.ToString(),
                CommandHelper.BuildKeyboard(keyboard));
        }