Esempio n. 1
0
        public async Task <IActionResult> AddList(string userId, string boardId, ListForCreationDto listForCreationDto)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized());
            }

            var currentUser = await _userManager.FindByIdAsync(userId);

            if (currentUser == null)
            {
                return(Unauthorized());
            }

            var board = await _repo.GetBoard(boardId);

            if (board == null)
            {
                return(BadRequest("board not found, refresh the page."));
            }

            if (!await _repo.UserInBoard(userId, boardId))
            {
                return(Unauthorized());
            }

            List list = _mapper.Map <List>(listForCreationDto);

            string listId = DateTime.Now.ToFileTime().ToString();

            listId = listId.Substring(listId.Length / 2, listId.Length / 4);

            list.Order  = board.Lists.Count;
            list.ListId = boardId + listId;

            var listToReturn = _mapper.Map <ListToReturnDto>(list);

            board.Lists.Add(list);

            if (await _repo.SaveAll())
            {
                return(Ok(new { list = listToReturn }));
            }

            return(BadRequest("Couldn't add the list. try refreshing the page."));
        }
Esempio n. 2
0
        public async Task <IActionResult> AddList(int id, ListForCreationDto listForCreationDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            listForCreationDto.Created  = DateTime.Now;
            listForCreationDto.UniqueId = RandomString(5);

            var list = _mapper.Map <List>(listForCreationDto);

            userFromRepo.Lists.Add(list);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Could not add list"));
        }