Exemplo n.º 1
0
        private static async Task <OwnedList> GetList(string listId, PortalUser user, IListRepository listRepository)
        {
            Guid id; var logger = StartEnumServer.Instance.GetLogger();

            OwnedList targetList = null;

            if (Guid.TryParse(listId, out id))
            {
                targetList = await listRepository.GetOwnedList(id);

                if (targetList.PortalUserID != user.PortalUserID)
                {
                    logger.LogError <MoveToListItemStep>(
                        $"Список {id} не принадлежит пользователю {user.PortalUserID}",
                        new LoggerParameter("ListId", id),
                        new LoggerParameter("PortalUserID", user.PortalUserID));
                    targetList = null;
                }
            }

            return(targetList);
        }
Exemplo n.º 2
0
        private async Task <ListItem> ProcessMove(MoveToListItemParams state, ListItem listItem, ListItem afterListItem, OwnedList targetList, IListItemRepository listItemRepository, IListRepository listRepository)
        {
            ListItem result = null;

            ListItem processedListItem;
            var      positions     = new List <Guid>();
            var      processedList = targetList;

            Guid listId;

            if (state.Copy)
            {
                processedListItem = listItemRepository.CreateNew(listItem.Content, state.User.PortalUserID);

                if (targetList != null)
                {
                    processedListItem.ListID = targetList.ListID;
                }
                else
                {
                    processedListItem.ListID = afterListItem.ListItemID;
                    processedList            = await listRepository.GetOwnedList(processedListItem.ListID);
                }

                await listItemRepository.SaveNew(processedListItem);

                result = processedListItem;

                foreach (var item in processedList.ListItem.OrderBy(i => i.OrderPosition))
                {
                    positions.Add(item.ListItemID);
                }

                listId = processedList.ListID;

                ReorderPositions(afterListItem, positions, processedListItem.ListItemID);
            }
            else
            {
                processedList = targetList;
                if (targetList != null && targetList.ListID != listItem.ListID)
                {
                    await listItemRepository.Delete(listItem.ListItemID);

                    await listItemRepository.ReorderItems(listItem.ListID);
                }

                if (processedList == null)
                {
                    processedList = await listRepository.GetOwnedList(afterListItem.ListID);
                }

                listId = processedList.ListID;

                if (processedList.ListID != listItem.ListID)
                {
                    listItem.ListID = processedList.ListID;
                    result          = listItem;
                    await listItemRepository.SaveNew(listItem);
                }

                foreach (var item in processedList.ListItem.OrderBy(i => i.OrderPosition))
                {
                    positions.Add(item.ListItemID);
                }

                if (positions.Contains(listItem.ListItemID))
                {
                    positions.Remove(listItem.ListItemID);
                }

                ReorderPositions(afterListItem, positions, listItem.ListItemID);
            }

            await listItemRepository.ReorderItems(listId, positions);

            return(result);
        }