コード例 #1
0
 public async Task <Response> Handle(Request request)
 {
     return(new Response()
     {
         Note = NoteApiModel.FromNote(await _context.Notes
                                      .Include(x => x.NoteTags)
                                      .Include("NoteTags.Tag")
                                      .Include(x => x.Tenant)
                                      .SingleAsync(x => x.Id == request.Id && x.Tenant.UniqueId == request.TenantUniqueId))
     });
 }
コード例 #2
0
            public async Task <Response> Handle(Request request)
            {
                var notes = await _context.Notes
                            .Include(x => x.NoteTags)
                            .Include("NoteTags.Tag")
                            .Where(x =>
                                   x.CreatedBy == request.Username &&
                                   x.Tenant.UniqueId == request.TenantUniqueId).ToListAsync();

                return(new Response()
                {
                    Notes = notes.Select(x => NoteApiModel.FromNote(x)).ToList()
                });
            }
コード例 #3
0
            public async Task <Response> Handle(Request request)
            {
                var note = await _context.Notes
                           .Include(x => x.NoteTags)
                           .Include("NoteTags.Tag")
                           .Include(x => x.Tenant).Where(x =>
                                                         x.CreatedBy == request.Username &&
                                                         x.Slug == request.Slug &&
                                                         x.Tenant.UniqueId == request.TenantUniqueId).SingleAsync();

                return(new Response()
                {
                    Note = NoteApiModel.FromNote(note)
                });
            }
コード例 #4
0
            public async Task <Response> Handle(Request request)
            {
                var entity = await _context.Notes
                             .Include(x => x.Tenant)
                             .SingleOrDefaultAsync(x => x.Id == request.Note.Id && x.Tenant.UniqueId == request.TenantUniqueId);

                if (entity == null)
                {
                    var tenant = await _context.Tenants.SingleAsync(x => x.UniqueId == request.TenantUniqueId);

                    var existingNote = await _context.Notes.SingleOrDefaultAsync(x => x.Title == request.Note.Title && x.CreatedBy == request.Username);

                    if (existingNote != null)
                    {
                        _bus.Publish(new AddedOrUpdatedNoteMessage(entity, request.CorrelationId, request.TenantUniqueId));
                        return(new Response());
                    }

                    _context.Notes.Add(entity = new Note()
                    {
                        TenantId = tenant.Id
                    });
                }

                entity.Title = request.Note.Title;

                entity.Body = request.Note.Body;

                entity.Slug = request.Note.Title.GenerateSlug();

                await _context.SaveChangesAsync(request.Username);

                _bus.Publish(new AddedOrUpdatedNoteMessage(NoteApiModel.FromNote(entity), request.CorrelationId, request.TenantUniqueId));

                return(new Response());
            }