public async Task <ToDo> AsyncInsertToDo(string Description, int Priority) { ToDo todo = new ToDo(Description, Priority); _context.Entry(todo).State = EntityState.Added; await _context.SaveChangesAsync(); return(todo); }
public async Task <ToDoItemModel> AddItemAsync(ToDoItemModel item) { var newEntity = Mapper.Map <TodoItemEntity>(item); newEntity.Operation = ClientShared.LocalData.Sync.SyncOperation.Insert; var tracker = toDoDataContext.Todos.Add(newEntity); var val = await toDoDataContext.SaveChangesAsync(); return(tracker.Entity); }
/// <summary> /// Add Type /// </summary> /// <param name="context"></param> /// <param name="AddTypeReguest"></param> /// <returns></returns> public async Task <ToDoTypeResponse> CreateToDoType(ToDoDataContext context, ToDoType AddTypeReguest) { ToDoType type = new ToDoType { Description = AddTypeReguest.Description }; context.ToDoType.Attach(entity: type); context.ToDoType.Add(type); var response = await context.SaveChangesAsync(); if (response != 1) { throw new Exception("Failed to save Types"); } var getSavedType = context.ToDoType.FirstOrDefault(t => t.Description == type.Description); ToDoTypeResponse typeResponse = new ToDoTypeResponse { TypeID = getSavedType.TypeID, Description = getSavedType.Description, IsActive = getSavedType.IsActive }; return(typeResponse); }
public async Task <ToDoListResponse> CreateToDoTask(ToDoDataContext context, ToDo AddToDoRequest) { ToDo toDo = new ToDo { //ToDoId = AddToDoRequest.ToDoId, Title = AddToDoRequest.Title, Notes = AddToDoRequest.Notes, DateCreated = DateTime.Now, ReminderDate = AddToDoRequest.ReminderDate, DueDate = AddToDoRequest.DueDate, IsDone = AddToDoRequest.IsDone, ToDoType = (ToDoTypeId)AddToDoRequest.ToDoType }; context.ToDo.Add(toDo); var response = await context.SaveChangesAsync(); var getTodo = context.ToDo.SingleOrDefault(getToDo => getToDo.ToDoId == toDo.ToDoId); if (getTodo == null) { throw new Exception("No Data found"); } var toDoListResponse = new ToDoListResponse { ToDoId = getTodo.ToDoId, Title = getTodo.Title, DateCreated = getTodo.DateCreated, ToDoType = getTodo.ToDoType, Notes = getTodo.Notes }; return(toDoListResponse); }
public async Task CreateToDo(ToDoItem toDo) { _toDoDataContext.Add(toDo); await _toDoDataContext.SaveChangesAsync(); }