public IHandlerBuilder Create(string title, IRequest request)
        {
            using var context = Database.Create();

            var letter = new Letter()
            {
                Title = title
            };

            letter.Status = LetterStatus.New;

            letter.Created  = DateTime.UtcNow;
            letter.Modified = DateTime.UtcNow;

            context.Letters.Add(letter);

            var announces = ExtractAnnounces(request, context);

            var order = 0;

            foreach (var announce in announces)
            {
                var letterAnnounce = new LetterAnnounce()
                {
                    Letter   = letter,
                    Announce = announce,
                    Order    = order++
                };

                context.LetterAnnounces.Add(letterAnnounce);
            }

            context.SaveChanges();

            return(Redirect.To("/letters/", true));
        }
        public IHandlerBuilder?AddAnnounces([FromPath] int id, IRequest request)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Include(l => l.Announces)
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            var highest = letter.Announces.Max(c => (int?)c.Order);

            int newOrder = (highest != null) ? (int)highest + 1 : 0;

            var announces = ExtractAnnounces(request, context);

            foreach (var announce in announces)
            {
                var letterAnnounce = new LetterAnnounce()
                {
                    Letter   = letter,
                    Announce = announce,
                    Order    = newOrder++
                };

                context.LetterAnnounces.Add(letterAnnounce);
            }

            context.SaveChanges();

            return(Redirect.To($"/letters/details/{id}/", true));
        }