public TodoModel SaveTodo(string login, TodoModel todo) { var todoEntity = _todoConverter.GetEntityByModel(todo); var user = _applicationContext.Users.FirstOrDefault(u => u.Login == login); user.Todos.Add(todoEntity); _applicationContext.SaveChanges(); return(_todoConverter.GetModelByEntity(todoEntity)); }
public TodolistModel AddTodo(TodolistModel newTodolist, string login) { var todolist = TDconverter.GetEntityByModel(newTodolist); _applicationContext.Users.Include(t => t.ToDoLists) .FirstOrDefault(u => u.Login == login).ToDoLists.Add(todolist); _applicationContext.SaveChanges(); return(newTodolist); }
public Todo GetEntityByModel(TodoModel model) { if (model == null) { return(null); } return(new Todo { Id = model.Id, Name = model.Name, Description = model.Description, Completed = model.Completed, Date = model.Date, Tags = model.Tags?.Select(t => _tagConverter.GetEntityByModel(t)).ToList() }); }