public Task <IActionResult> Detail(string entryId, string imageId) => RunEntryAsync(entryId, Permission.Read, async entry => { Image entity = await dataContext.Images.FirstOrDefaultAsync(i => i.Entry.Id == entryId && i.Id == imageId); if (entity == null) { return(NotFound()); } var model = new ImageModel(); service.MapEntityToModel(entity, model, entry.UserId); var permission = model.UserId == User.FindUserId() || await shareStatus.IsEntrySharedForWriteAsync(entryId, User.FindUserId()) ? Permission.Write : Permission.Read; AuthorizedModel <ImageModel> result = new AuthorizedModel <ImageModel>(model); result.OwnerId = entry.UserId; result.OwnerName = await userNames.GetUserNameAsync(entry.UserId); result.UserPermission = permission; return(Ok(result)); });
public async Task <ActionResult <AuthorizedModel <EntryModel> > > Get(string id) { Ensure.NotNullOrEmpty(id, "id"); Entry entity = await db.Entries.FindAsync(id); if (entity == null) { return(NotFound()); } Permission permission = Permission.Write; string userId = HttpContext.User.FindUserId(); if (entity.UserId != userId) { if (!await shareStatus.IsEntrySharedForReadAsync(id, userId)) { return(Unauthorized()); } if (!await shareStatus.IsEntrySharedForWriteAsync(id, userId)) { permission = Permission.Read; } } EntryModel model = new EntryModel(); MapEntityToModel(entity, model); AuthorizedModel <EntryModel> result = new AuthorizedModel <EntryModel>(model); result.OwnerId = entity.UserId; result.OwnerName = await userNames.GetUserNameAsync(entity.UserId); result.UserPermission = permission; return(Ok(result)); }
public Task <IActionResult> Get(string id) => RunBeingAsync(id, Permission.Read, async entity => { Permission permission = Permission.Write; string userId = HttpContext.User.FindUserId(); if (entity.UserId != userId) { if (!await shareStatus.IsBeingSharedForWriteAsync(id, userId)) { permission = Permission.Read; } } BeingModel model = new BeingModel(); MapEntityToModel(entity, model); AuthorizedModel <BeingModel> result = new AuthorizedModel <BeingModel>(model); result.OwnerId = entity.UserId; result.OwnerName = await userNames.GetUserNameAsync(entity.UserId); result.UserPermission = permission; return(Ok(result)); });
public async Task <DashboardViewModel> GetDashboardViewModelAsync() { var userName = await _userNameProvider.GetUserNameAsync(); var wallets = await _walletsProvider.GetAllWalletsAsync(); var transactions = await _transactionsProvider.GetTransactionsAsync(); var timeBalance = await _timeBalanceProvider.GetTimeBalanceAsync(new GetTimeBalanceRequest(new LastMonthTimeBalanceSearchRange())); var walletViewModels = _mapper.Map <IEnumerable <WalletViewModel> >(wallets).ToList(); walletViewModels.Add(WalletViewModel.CreateNewWalletViewModel()); return(new DashboardViewModel() { UserName = userName, CurrentBalance = _mapper.Map <CurrentBalanceViewModel>(wallets), Transactions = _mapper.Map <IEnumerable <TransactionViewModel> >(transactions), Wallets = walletViewModels.ToImmutableArray(), TimeBalance = _mapper.Map <TimeBalanceViewModel>(timeBalance) }); }
protected override async void Loaded() { UserName = await _userNameProvider.GetUserNameAsync(); }