Exemplo n.º 1
0
        /// <summary>
        /// Adds a todo-item to the data context.
        /// </summary>
        /// <param name="item">Item to add.</param>
        /// <returns>Primary key for inserted item.</returns>
        public async Task <int> AddTodo(TodoViewModel item)
        {
            using (var context = new TolldoDbContext())
            {
                // Create item to add
                var itemToAdd = _mapper.Map <Todo>(item);

                // Add item to database
                context.Add(itemToAdd);
                await context.SaveChangesAsync();

                return(itemToAdd.Id);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a subtask-item to the data context.
        /// </summary>
        /// <param name="item">Item to add.</param>
        /// <param name="id">Foreign key to the item.</param>
        /// <returns>Primary key for inserted item.</returns>
        public async Task <int> AddSubtask(SubtaskViewModel item, int id)
        {
            using (var context = new TolldoDbContext())
            {
                // Create item to add
                var itemToAdd = _mapper.Map <Subtask>(item);

                // Add foreign key
                itemToAdd.TodoTaskId = id;

                // Add item to database
                context.Add(itemToAdd);
                await context.SaveChangesAsync();

                return(itemToAdd.Id);
            }
        }