public ToDoListDTO GetToDoListShare(Guid shareId)
        {
            ToDoListShare share = _context.ToDoListShares.Include(s => s.ToDoList)
                                  .ThenInclude(l => l.Items)
                                  .Where(s => s.Id == shareId && DateTime.Compare(s.ExpiresOn, DateTime.Now) > 0)
                                  .SingleOrDefault();

            if (share == null)
            {
                throw new EntityNotFoundException();
            }

            return(new ToDoListDTO(share.ToDoList));
        }
        public ActionResult CreateToDoListShare([FromRoute] Guid listId)
        {
            _logger.LogInformation("ToDoList.CreateToDoListShare() executed!");

            try
            {
                ToDoListShare createdShare = _service.CreateToDoListShare(listId, User.GetEmail());
                return(CreatedAtAction(nameof(GetToDoListShare), new { shareId = createdShare.Id }, createdShare.Id));
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }
            catch (UnauthorizedException)
            {
                return(Unauthorized());
            }
        }
        public ToDoListShare CreateToDoListShare(Guid listId, string owner)
        {
            ToDoList toDoList = GetToDoList(listId, owner);

            if (toDoList == null)
            {
                throw new EntityNotFoundException();
            }
            else if (toDoList.Owner != owner)
            {
                throw new UnauthorizedException();
            }

            ToDoListShare share = new ToDoListShare(toDoList);

            _context.ToDoListShares.Add(share);
            _context.SaveChanges();

            return(share);
        }