Пример #1
0
        public async Task <ActionResult <Comment> > PostComment(Comment comment)
        {
            _context.Comments.Add(comment);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetComment", new { id = comment.CommentId }, comment));
        }
Пример #2
0
        public async Task <bool> AddRange(List <ItemCreateDto> items, string email)
        {
            // Bax gor basqa userin todo-suna item elave eliyirmi:
            foreach (var item in items)
            {
                var todo = await _context.Todos
                           .FirstOrDefaultAsync(t => t.Id == item.TodoId &&
                                                t.Author.NormalizedEmail == email);

                if (todo == null)
                {
                    return(false);
                }
            }

            // Herseyi Item listinin icine yigib added olaraq track ele:
            var newItems = new List <Item>();

            for (int i = 0; i < items.Count(); i++)
            {
                newItems.Add(new Item()
                {
                    Content = items[i].Content,
                    isDone  = items[i].IsDone,
                    Order   = items[i].Order,
                    TodoId  = items[i].TodoId
                });
            }
            await _context.Items.AddRangeAsync(newItems);

            var res = await _context.SaveChangesAsync();

            return(res > 0);
        }
Пример #3
0
        public async Task <IActionResult> AddTodo(string user, [FromBody] AddTodoModel model)
        {
            if (!TodoAppUser.IsAllowed(user))
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var todo = new Todo
            {
                // Don't do this at home!
                Id            = db.Todos.Max(t => t.Id) + 1,
                AddedAt       = DateTimeOffset.Now,
                LastUpdatedAt = DateTimeOffset.Now,
                IsComplete    = false,
                UserName      = user,
                Description   = model.Description
            };

            db.Todos.Add(todo);

            await db.SaveChangesAsync();

            return(Ok(todo));
        }
Пример #4
0
        public async Task <Todo> Create(Todo todo)
        {
            _context.Todos.Add(todo);
            await _context.SaveChangesAsync();

            return(todo);
        }
Пример #5
0
        public async Task <ActionResult <TodoItem> > Post(TodoItem item)
        {
            _context.TodoItems.Add(item);
            await _context.SaveChangesAsync();

            return(Ok(item));
        }
Пример #6
0
        public async Task <ActionResult <Models.Task> > PostTask(Models.Task task)
        {
            _context.Tasks.Add(task);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTask", new { id = task.TaskId }, task));
        }
Пример #7
0
        public async Task <ActionResult <TaskList> > PostTaskList(TaskList taskList)
        {
            _context.TaskLists.Add(taskList);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTaskList", new { id = taskList.TaskListId }, taskList));
        }
Пример #8
0
        public async Task <IActionResult> PutTodo(int id, Todo todo)
        {
            if (id != todo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(todo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #9
0
        public async Task <TodoItem> AddTodoItem(Models.TodoItem value, int userId)
        {
            var existingTags = await _context.Tags
                               .Where(t => value.Tags.Contains(t))
                               .ToDictionaryAsync(t => t.Name);

            var item = new TodoItem
            {
                Title       = value.Title,
                Description = value.Description,
                OwnerId     = userId,

                Completed = null,
                Created   = DateTime.Now,
            };

            await UpdateTodoTags(item, value.Tags);

            _context.Add(item);

            await _context.SaveChangesAsync();

            StopTracking(item);

            return(item);
        }
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #11
0
        public async Task <IActionResult> Create(TodoList list)
        {
            _context.TodoLists.Add(list);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetTodoList", new { id = list.ID }, list));
        }
        public async Task <IActionResult> Post([FromBody] TodoItem item)
        {
            if (item is null)
            {
                return(BadRequest());
            }

            await _context.AddAsync(item);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                // TODO: Insert logging here

                // The new entity could not be committed to the database.
                // RFC 2616 Section 10.5 recommends that an explanation to be provided
                // for 500 responses.
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Could not commit new entity to the database"));
            }

            return(CreatedAtRoute("GetTodo", new { id = item.Id }, item));
        }
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem todoItem)
        {
            _context.TodoItems.Add(todoItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTodoItem", new { id = todoItem.ID }, todoItem));
        }
Пример #14
0
        public async Task <IActionResult> Create(TodoItem item)
        {
            _context.TodoItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetTodo", new { id = item.ID }, item));
        }
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutTodoList([FromRoute] int id, [FromBody] TodoList todoList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != todoList.ID)
            {
                return(BadRequest());
            }

            _context.Entry(todoList).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #17
0
        public async Task <ActionResult <UserTaskViewModel> > PatchUserTask(int id, UserTaskDTO userTaskUpdate)
        {
            var userTask = await _context.UserTasks.FindAsync(id);

            if (userTask == null)
            {
                return(NotFound());
            }

            userTask.Name   = userTaskUpdate.Name ?? userTask.Name;
            userTask.Status = userTaskUpdate.Status;
            userTask.User   = await _context.Users.FindAsync(userTaskUpdate.UserId);

            userTask.Deadline = userTaskUpdate.Deadline;

            _context.Entry(userTask).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(new UserTaskViewModel
            {
                Id = userTask.Id,
                Name = userTask.Name ?? "No-name",
                Deadline = userTask.Deadline ?? DateTime.Now,
                UserId = userTask?.User.Id,
                Status = userTask?.Status.ToString() ?? Models.TaskStatus.New.ToString(),
                GroupId = userTask?.TaskGroup?.Id
            });
        }
Пример #18
0
        public async void ChangeStateTodo(Guid id, TodoState state)
        {
            var todo = _context.Todo.Where(t => t.Id.Equals(id)).FirstOrDefault();

            todo.State = state;
            await _context.SaveChangesAsync();
        }
Пример #19
0
        public async Task Delete(TodoAggregate item)
        {
            var entity = m_dbContext.Todos.Where(dl => dl.Id == item.Id).FirstOrDefault();

            m_dbContext.Todos.Remove(entity);

            await m_dbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> Post([FromBody] TodoItem todoItem)
        {
            await _context.TodoItems.AddAsync(todoItem);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetTodoItem", new { id = todoItem.ID }, todoItem));
        }
Пример #21
0
        public async Task <TodoItem> AddAsync(Collection collection, TodoItem item)
        {
            _database.Attach(collection);
            collection.TodoItems.Add(item);
            await _database.SaveChangesAsync();

            return(item);
        }
Пример #22
0
        public async Task <Column> InsertColumnAsync(Column column)
        {
            DAL.Column newColumn = new() { Title = column.Title };
            _context.Columns.Add(newColumn);
            await _context.SaveChangesAsync();

            return(await GetSingleColumnAsync(newColumn.Id));
        }
Пример #23
0
        public async Task <ActionResult> PostAsync([FromBody] TodoItem item)
        {
            await _dbContext.TodoItems.AddAsync(item);

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Пример #24
0
        public async Task <T> AddAsync(T entity)
        {
            await _dbContext.Set <T>().AddAsync(entity);

            await _dbContext.SaveChangesAsync();

            return(entity);
        }
    public async Task <int> Add(Todo todo)
    {
        await _context.Todos.AddAsync(todo);

        await _context.SaveChangesAsync();

        return(todo.Id);
    }
Пример #26
0
        public async Task <IActionResult> OnPostCreateAsync()
        {
            await _db.TodoItems.AddAsync(TodoItem);

            await _db.SaveChangesAsync();

            return(RedirectToPage());
        }
Пример #27
0
        public async Task <Collection> AddAsync(Collection collection)
        {
            var value = _database.Add(collection);
            await _database.SaveChangesAsync();

            value.State = EntityState.Detached;
            return(value.Entity);
        }
Пример #28
0
 public async Task AddAsync(TodoItem todoItem)
 {
     if (_context.TodoItem.Any(s => s.Id == todoItem.Id))
     {
         throw new DuplicateTodoItemException(" duplicate id: { " + todoItem.Id + "}");
     }
     _context.TodoItem.Add(todoItem);
     await _context.SaveChangesAsync();
 }
Пример #29
0
        public async Task <IActionResult> Post([FromBody] TodoBag value)
        {
            var todo = Todo.CreateFrom(value);

            _context.Add(todo);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = todo.Id }, todo));
        }
        public async Task <ActionResult <TodoItem> > AddTodoItemAsync(TodoItem item)
        {
            await Task.Delay(Config.ActionDelay);

            _dbContext.TodoItems.Add(item);
            await _dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItemAsync), new { id = item.Id }, item));
        }