public UndoRedoRequestHandler(ILogger <UndoRedoRequestHandler> logger, IUserAccountRepository userAccountRepository, IUserActionsService userActionsService) { _logger = logger; _userActionsService = userActionsService; _userAccountRepository = userAccountRepository; }
public AddItemApiRequestHandler(ILogger <AddItemApiRequestHandler> logger, IUserListRepository userListRepository, IUserItemRepository userItemRepository, IUserActionsService userActionsService) { _logger = logger; _userListRepository = userListRepository; _userItemRepository = userItemRepository; _userActionsService = userActionsService; }
public ReorderItemRequestHandler(ILogger <ReorderItemRequestHandler> logger, IUserAccountRepository userAccountRepository, IUserItemRepository userItemRepository, IUserListRepository userListRepository, IUserActionsService userActionsService) { _logger = logger; _userAccountRepository = userAccountRepository; _userItemRepository = userItemRepository; _userActionsService = userActionsService; }
public void ShouldGetDifferentImplementationFromResolveContextForUser() { IIdentity identity = new AppIdentity(); // three principals, one for each role var adminPrincipal = new AppPrincipal(identity, new[] { "Admin" }); var salesPrincipal = new AppPrincipal(identity, new[] { "Sales" }); var customerPrincipal = new AppPrincipal(identity, new[] { "Customer" }); var container = new Container(); container.RegisterType <AdminActionsService>(); container.RegisterType <SalesActionsService>(); container.RegisterType <CustomerActionsService>(); container.RegisterType <UserControlPanel>(); // register delegate to read the CurrentPrincipal property, to make it dynamic container.RegisterDelegate(() => CurrentPrincipal); // now register the delegate handler for the IUserActionsService, which does the // role sniffing over the principal container.RegisterDelegate((IPrincipal p, ResolveContext rc) => { IUserActionsService toReturn = null; if (p != null) { if (p.IsInRole("Customer")) { toReturn = rc.Resolve <CustomerActionsService>(); } else if (p.IsInRole("Sales")) { toReturn = rc.Resolve <SalesActionsService>(); } else if (p.IsInRole("Admin")) { toReturn = rc.Resolve <AdminActionsService>(); } } return(toReturn); }); // set the principal, and resolve CurrentPrincipal = adminPrincipal; var result1 = container.Resolve <UserControlPanel>(); // now swap principals CurrentPrincipal = salesPrincipal; var result2 = container.Resolve <UserControlPanel>(); // and again CurrentPrincipal = customerPrincipal; var result3 = container.Resolve <UserControlPanel>(); Assert.IsType <AdminActionsService>(result1.ActionsService); Assert.IsType <SalesActionsService>(result2.ActionsService); Assert.IsType <CustomerActionsService>(result3.ActionsService); }
public GetListItemsRequestHandler(ILogger <GetListItemsRequestHandler> logger, IUserAccountRepository userAccountRepository, IUserListRepository userListRepository, IUserItemRepository userItemRepository, IUserActionsService userActionsService, IUserActionRepository userActionRepository) { _logger = logger; _userAccountRepository = userAccountRepository; _userListRepository = userListRepository; _userItemRepository = userItemRepository; _userActionsService = userActionsService; _userActionRepository = userActionRepository; }
public UserControlPanel(IUserActionsService actionsService) { ActionsService = actionsService; }
public MeController(IUserActionsService usuarioAcoesService) { this.usuarioAcoesService = usuarioAcoesService; }
public UserActionController(IUserActionsService userActionsService) { _userActionsService = userActionsService; }
public async Task AddItemAsync(UserAccount user, UserList list, string description, string notes, DateTime?dueDate, ItemRepeat?repeat, IUserActionsService userActions) { var maxSortOrder = await GetMaxSortOrderAsync(user, list?.UserListId); var newUserItem = new UserItem { UserAccount = user, UserList = list, Description = description, Notes = notes, NextDueDate = dueDate, Repeat = repeat, SortOrder = maxSortOrder + 1 }; _context.UserItems.Add(newUserItem); await _context.SaveChangesAsync(); var savedItemSortOrders = new List <(int, int, int)>(); if (list?.ItemSortOrder != null) { await UpdateOrderAsync(user, list, list.ItemSortOrder, savedItemSortOrders); } await userActions.AddAsync(user, new AddItemAction(newUserItem, savedItemSortOrders)); }
public async Task UpdateOrderAsync(UserAccount user, UserItem item, UserItem precedingItem, IUserActionsService userActions) { var savedItemSortOrders = new List <(int, int, int)>(); var items = _context.UserItems .Where(i => i.UserItemId != item.UserItemId && i.UserAccountId == item.UserAccountId && i.UserListId == item.UserListId && i.CompletedDateTime == null && i.DeletedDateTime == null) .OrderBy(i => i.SortOrder); var sortOrder = 0; var now = DateTime.UtcNow; if (precedingItem == null) { UpdateItemSortOrder(item, sortOrder++, now, savedItemSortOrders); } await foreach (var i in items.AsAsyncEnumerable()) { UpdateItemSortOrder(i, sortOrder++, now, savedItemSortOrders); if (precedingItem?.UserItemId == i.UserItemId) { UpdateItemSortOrder(item, sortOrder++, now, savedItemSortOrders); } } var savedListSortOrder = ((int?)null, (ItemSortOrder?)null, (ItemSortOrder?)null); var list = item.UserListId == null ? null : await _context.UserLists.SingleOrDefaultAsync(l => l.UserListId == item.UserListId && l.DeletedDateTime == null); if (list != null) { savedListSortOrder = (list.UserListId, list.ItemSortOrder, null); list.ItemSortOrder = null; list.LastUpdateDateTime = now; } await _context.SaveChangesAsync(); await userActions.AddAsync(user, new ReorderItemsAction(savedItemSortOrders, savedListSortOrder)); void UpdateItemSortOrder(UserItem itemToUpdate, int newSortOrder, DateTime lastUpdateDateTime, IList <(int UserItemId, int OriginalSortOrder, int UpdatedSortOrder)> collectItemChanges) { if (itemToUpdate.SortOrder == newSortOrder) { return; } collectItemChanges.Add((itemToUpdate.UserItemId, itemToUpdate.SortOrder, newSortOrder)); itemToUpdate.SortOrder = newSortOrder; itemToUpdate.LastUpdateDateTime = lastUpdateDateTime; } }