public async Task <Response> Handle(Request request) { var entity = await _context.HomePages .Include(x => x.Tenant) .SingleOrDefaultAsync(x => x.Tenant.UniqueId == request.TenantUniqueId); if (entity == null) { var tenant = await _context.Tenants.SingleAsync(x => x.UniqueId == request.TenantUniqueId); _context.HomePages.Add(entity = new HomePage() { TenantId = tenant.Id }); } entity.AvatarImageUrl = request.HomePage.AvatarImageUrl; entity.Name = request.HomePage.Name; entity.Title = request.HomePage.Title; await _context.SaveChangesAsync(request.Username); _cache.Remove(HomePagesCacheKeyFactory.Get(request.TenantUniqueId)); return(new Response()); }
public async Task <Response> Handle(Request request) { var homePage = await _cache.FromCacheOrServiceAsync(() => _context.HomePages .Include(x => x.Tenant) .SingleOrDefaultAsync(x => x.Tenant.UniqueId == request.TenantUniqueId), HomePagesCacheKeyFactory.Get(request.TenantUniqueId)); return(new Response() { HomePage = homePage == null ? null : HomePageApiModel.FromHomePage(homePage) }); }