コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: ToDoTypes.cs プロジェクト: DidaR02/RemindMe
        /// <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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public async Task CreateToDo(ToDoItem toDo)
 {
     _toDoDataContext.Add(toDo);
     await _toDoDataContext.SaveChangesAsync();
 }