Exemple #1
0
        public override async Task <Response> Handle(Request message, CancellationToken cancellationToken)
        {
            var Magic = await this.context.Magics
                        .Include(a => a.CreatedByUser)
                        .SingleNotDeletedOrExceptionAsync(t => t.Id == message.Id, cancellationToken: cancellationToken);

            Magic.Close();
            await this.context.SaveChangesAsync(cancellationToken);

            var user  = Magic.CreatedByUser;
            var model = new MagicClosedEmail.Model(user.Id, "", user.Name, user.Email,
                                                   MagicDetails.Button(Magic.Id).AsUrl(this.appConfig.Value));

            await this.emailSender.SendEmail(user.Email, model);

            this.notificationsDbContext.Add(
                new Notification(
                    new EntityReference(NotificationRecipientType.UserId.Value, user.Id.ToString()),
                    new EntityReference(MagicNotificationManager.Key, Magic.Id.ToString()),
                    $"Magic #{Magic.Id} closed",
                    null));

            await this.notificationsDbContext.SaveChangesAsync(cancellationToken);

            return(new Response()
                   .WithGrowlMessage($"Magic #{Magic.Id} was closed.", GrowlNotificationStyle.Success));
        }
 public Item(Magic t, ActionList actions)
 {
     this.Id        = MagicDetails.Button(t.Id);
     this.Title     = t.Title;
     this.Details   = t.Details.AsHtmlString();
     this.Status    = t.GetStatus();
     this.Actions   = actions;
     this.CreatedOn = t.CreatedOn;
 }
        public override async Task <Response> Handle(Request message, CancellationToken cancellationToken)
        {
            var Magic = await this.context.Magics
                        .SingleNotDeletedOrExceptionAsync(t => t.Id == message.Id, cancellationToken : cancellationToken);

            Magic.Submit();
            await this.context.SaveChangesAsync(cancellationToken);

            var supervisors = await this.userManager.GetUsersInRoleAsync(CoreRoles.Supervisor.Name);

            foreach (var user in supervisors)
            {
                var model = new MagicSubmittedEmail.Model("", user.UserName, user.Email, MagicDetails.Button(Magic.Id).AsUrl(this.appConfig.Value));
                await this.emailSender.SendEmail(user.Email, model);

                this.notificationsDbContext.Add(
                    new Notification(
                        new EntityReference(NotificationRecipientType.UserId.Value, user.Id.ToString()),
                        new EntityReference(MagicNotificationManager.Key, Magic.Id.ToString()),
                        $"New Magic submitted",
                        null));
            }

            await this.notificationsDbContext.SaveChangesAsync(cancellationToken);

            return(new Response()
                   .WithGrowlMessage($"Magic #{Magic.Id} was submitted.", GrowlNotificationStyle.Success));
        }