Exemplo n.º 1
0
        public ToDoListDTO CreateToDoList(ToDoListDTO toDoListDTO, string email)
        {
            _logger.LogInformation("ToDoListService -> Executing CreateToDoList()");

            //if the user didn't specify the date for the reminder
            if (toDoListDTO.EndDate == null)
            {
                toDoListDTO.IsReminded = false; //the list is not a reminded list
            }
            else
            {
                toDoListDTO.IsReminded = true;
            }

            ToDoList newList = toDoListDTO.CreateEntity(email);

            //new todo list position is 'highest' in the hierarchy for the specified user
            newList.Position = _context.ToDoLists
                               .Where(x => x.Owner.Equals(email))
                               .Count();

            _context.ToDoLists.Add(newList);
            _context.SaveChanges();

            toDoListDTO.Id       = newList.Id;
            toDoListDTO.Position = newList.Position;

            return(toDoListDTO);
        }
Exemplo n.º 2
0
        public ToDoListDTO UpdateToDoList(Guid id, ToDoListDTO toDoListDTO, string email)
        {
            _logger.LogInformation("ToDoListService -> Executing UpdateToDoList()");

            //if the user didn't specify the date for the reminder
            if (toDoListDTO.EndDate == null)
            {
                toDoListDTO.IsReminded = false; //the list is not a reminded list
            }
            else
            {
                toDoListDTO.IsReminded = true;
            }

            ToDoList listToUpdate = _context
                                    .ToDoLists
                                    .Include(todo => todo.Items)
                                    .SingleOrDefault(todo => todo.Id.Equals(id) && todo.Owner.Equals(email));

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

            listToUpdate.UpdateData(toDoListDTO.CreateEntity(email));
            _context.SaveChanges();
            return(new ToDoListDTO(listToUpdate)); //return an updated dto
        }