Exemplo n.º 1
0
        public async Task <int> CreateAsync(CreateList model, IValidator <CreateList> validator)
        {
            ValidateAndThrow(model, validator);

            var list = _mapper.Map <ToDoList>(model);

            list.Name        = list.Name.Trim();
            list.CreatedDate = list.ModifiedDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(model.TasksText))
            {
                list.Tasks = model.TasksText.Split("\n")
                             .Where(task => !string.IsNullOrWhiteSpace(task))
                             .Select(task => new ToDoTask
                {
                    Name         = task.Trim(),
                    IsOneTime    = list.IsOneTimeToggleDefault,
                    CreatedDate  = list.CreatedDate,
                    ModifiedDate = list.CreatedDate
                }
                                     ).ToList();
            }

            return(await _listsRepository.CreateAsync(list));
        }