public async Task RemoveListAsync(int userId, List list) { var check = await _listRepository.GetListAsync(userId, list.Id); if (check == null || check.UserId != userId) { throw new ForbiddenException(Constants.Messages.Access.RemoveList); } await _listRepository.RemoveAsync(check); }
public async Task<List> AddListAsync(int userId, string title) { var list = new List { Title = title, UserId = userId, CreatedDate = _dateTimeService.UtcNow }; return await _listRepository.AddAsync(list); }
public async Task<List> CopyListAsync(int userId, int listId) { var list = await _listRepository.GetListAsync(userId, listId); if (list == null) { throw new ForbiddenException(Constants.Messages.Access.CopyList); } var newlist = new List { Title = list.Title, UserId = userId, CreatedDate = _dateTimeService.UtcNow }; newlist = await _listRepository.AddAsync(newlist); var newListGoods = (await _listGoodRepository.GetListGoodsAsync(listId)) .Select(lp => { lp.Id = 0; lp.ListId = newlist.Id; lp.Completed = false; lp.CompletedDate = null; lp.CompletedUserId = null; return lp; }) .ToList(); await _listGoodRepository.AddListOfListGood(newListGoods); newlist.ListGoods = newListGoods; return newlist; }