コード例 #1
0
        public async Task <IActionResult> PutTasksDetails([FromRoute] int id, [FromBody] TasksDetails tasksDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
コード例 #2
0
ファイル: TasksController.cs プロジェクト: PetkoG/TaskList
        public async Task <IActionResult> PutTaskEntity(int id, TaskEntity taskEntity)
        {
            if (id != taskEntity.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <ActionResult> New(TaskItem task)
        {
            _tasksContext.Tasks.Add(task);
            await _tasksContext.SaveChangesAsync();

            return(RedirectToAction("Index", await _tasksContext.Tasks.ToListAsync()));
        }
コード例 #4
0
        public async Task <ActionResult <DataAccess.Models.Task> > Update(int userId, int id, PutTaskParam task)
        {
            try
            {
                if (id != task.Id)
                {
                    return(BadRequest());
                }

                DataAccess.Models.Task t = await _context.Tasks.FindAsync(task.Id);

                if (t != null)
                {
                    t.UserId                = userId;
                    t.Description           = task.Description;
                    t.State                 = task.State;
                    _context.Entry(t).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(NotFound($"Could not find Task {id}"));
                }

                return(Ok(t));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
コード例 #5
0
        public async Task <Itam> AddAsync(Itam i)
        {
            await _context.Tasks.AddAsync(i);

            await _context.SaveChangesAsync();

            return(i);
        }
コード例 #6
0
        public async Task <IActionResult> Delete(int id)
        {
            var task = await _tasksContext.Tasks.FindAsync(id);

            _tasksContext.Tasks.Remove(task);
            await _tasksContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description")] Project project)
        {
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Id,Name,IsDone")] TableTasks tableTasks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tableTasks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tableTasks));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Models.Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
コード例 #10
0
        //Status後で追加
        public async Task <IActionResult> Create([Bind("ID,Category,ProjectName,StartDate,CompletionDate,Status,Priority,Comment")] Project project)
        {
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
コード例 #11
0
        public async ThreadingTasks.Task <IActionResult> Create([Bind("TaskID,TaskTitle")] Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("Id,JavascriptCode")] Tasks tasks)
        {
            if (ModelState.IsValid)
            {
                tasks.Id = Guid.NewGuid();
                _context.Add(tasks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tasks));
        }
コード例 #13
0
        public async Task <IActionResult> Create([Bind("Id,InputParams,Finished,Resoult")] TaskInstance taskInstance)
        {
            if (ModelState.IsValid)
            {
                taskInstance.Id = Guid.NewGuid();
                _context.Add(taskInstance);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(taskInstance));
        }
コード例 #14
0
        public async Task <IActionResult> Create([Bind("ID,ProjectID,Process,TaskName,Start,End,Status,Progress,Memo")] Thing thing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(thing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectID"] = new SelectList(_context.Projects, "ID", "ProjectName", thing.ProjectID);
            return(View(thing));
        }
コード例 #15
0
        public async Task <IActionResult> Create([Bind("Id,Title,Priority,Deadline,IsCompleted,ProjectId")] Models.Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.Projects, "Id", "Title", task.ProjectId);
            return(View(task));
        }
コード例 #16
0
        public async Task <ProjectTaskResponse> ExecuteAsync(CreateTaskRequest request)
        {
            var task = new ProjectTask
            {
                ParentId  = request.ParentId,
                ProjectId = (int)request.ProjectId, //dirty code
                Priority  = (Entities.TaskPriority)request.Priority,
                Title     = request.Title,
                DueDate   = request.DueDate
            };
            await _context.Tasks.AddAsync(task);

            await _context.SaveChangesAsync();

            if (request.ParentId.HasValue)
            {
                var parent = await _context.Tasks.FindAsync(request.ParentId.Value);

                if (parent != null)
                {
                    parent.Childrens.Add(task);
                }
            }
            //TODO: add automapper
            return(new ProjectTaskResponse
            {
                DueDate = task.DueDate,
                Id = task.Id,
                ParentId = task.ParentId,
                Priority = (ViewModels.Tasks.TaskPriority)task.Priority,
                Title = task.Title
            });
        }
コード例 #17
0
ファイル: ContextTests.cs プロジェクト: vnikifirov/DotNet
        public async Task Projects_AddNewProject_ShouldOk()
        {
            // Create new project
            var created = new Context.Models.Project
            {
                Name       = "At work activities",
                Start      = DateTime.Now,
                Completion = DateTime.Now.AddDays(5),
                Priority   = 1,
                Status     = Context.Models.ProjectStatus.NotStarted
            };

            // Assign as global var
            _project = created;

            // Add new project into DB context
            await _context.Projects.AddAsync(created);

            // Update DB (InMemory)
            Assert.DoesNotThrowAsync(async() => await _context.SaveChangesAsync());

            // Check that project was created
            Assert.NotNull(created);

            // Check that project was added in DB context
            var projectName = (await _context.Projects.FirstOrDefaultAsync()).Name;

            Assert.AreEqual(projectName, created.Name);
        }
コード例 #18
0
        public async Task ExecuteAsync(ArchiveProjectRequest request)
        {
            //TODO: check if user allowed to archive this project
            var project = await _context.Projects.FindAsync(request.ProjectId);

            if (project != null && !project.Archived)
            {
                project.Archived = true;
                await _context.SaveChangesAsync();
            }
        }
コード例 #19
0
        public async Task ExecuteAsync(int taskId)
        {
            //TODO: use one query instead of two
            var task = await _context.Tasks.FindAsync(taskId);

            if (task != null)
            {
                await removeTaskWithChildren(task);

                await _context.SaveChangesAsync();
            }
        }
コード例 #20
0
        public async Task <ActionResult <TaskDtoToReturn> > AddTask(TaskDtoForCreate taskDto)
        {
            var userId = HttpContext.User?.Claims?.FirstOrDefault(c => c.Type == "userid")?.Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, new Response {
                    Status = "Error", Message = "Invalid token"
                }));
            }


            var task = mapper.Map <TaskC>(taskDto);
            await context.Tasks.AddAsync(task);

            task.UserId = userId;


            task.TaskTags = new List <TaskTag>();
            if (taskDto.TagIds != null)
            {
                foreach (var tagId in taskDto.TagIds)
                {
                    var tag = await context.Tags.FindAsync(tagId);

                    if (tag == null)
                    {
                        return(StatusCode(StatusCodes.Status400BadRequest, new Response {
                            Status = "Error", Message = "Failed to find tag"
                        }));
                    }
                    if (tag.UserId != userId)
                    {
                        return(StatusCode(StatusCodes.Status400BadRequest, new Response {
                            Status = "Error", Message = "Unauthorized tag id"
                        }));
                    }

                    var taskTag = new TaskTag()
                    {
                        Tag  = tag,
                        Task = task
                    };

                    task.TaskTags.Add(taskTag);
                }
            }

            if (await context.SaveChangesAsync() == 0)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, new Response {
                    Status = "Error", Message = "Failed to create task"
                }));
            }

            return(mapper.Map <TaskDtoToReturn>(task));
        }
コード例 #21
0
        public async Task <ProjectResponse> ExecuteAsync(CreateProjectRequest request, string userId)
        {
            var project = new Project
            {
                Title       = request.Title,
                Description = request.Description,
                OwnerId     = Guid.Parse(userId)
            };
            await _context.Projects.AddAsync(project);

            await _context.SaveChangesAsync();

            return(new ProjectResponse {
                Title = project.Title, Description = project.Description, Id = project.Id
            });
        }
コード例 #22
0
        public async Task <bool> ExecuteAsync(int projectId)
        {
            var project = await _context.Projects.FindAsync(projectId);

            //TODO: check if user is owner of project before trying to restore it from archive
            if (project != null)
            {
                project.Archived = false;
                await _context.SaveChangesAsync();

                return(true);
            }
            else
            {
                //project not found
                return(false);
            }
        }
コード例 #23
0
        public async Task <ProjectTaskResponse> ExecuteAsync(int taskId, UpdateTaskRequest request)
        {
            var foundTask = await _context.Tasks.FindAsync(taskId);

            if (foundTask != null)
            {
                //TODO: check if user is owner of project
                if (request.DueDate.HasValue)
                {
                    if (request.DueDate.Value < DateTime.Now)
                    {
                        //throw exception?
                    }
                    foundTask.DueDate = request.DueDate.Value;
                }
                if (request.Completed.HasValue)
                {
                    foundTask.Completed = request.Completed.Value;
                }
                if (!string.IsNullOrEmpty(request.Title))
                {
                    foundTask.Title = request.Title;
                }
                if (request.Priority.HasValue)
                {
                    foundTask.Priority = (Entities.TaskPriority)request.Priority.Value;
                }
            }
            await _context.SaveChangesAsync();

            //TODO: add automapper
            return(foundTask == null ? null : new ProjectTaskResponse
            {
                Title = foundTask.Title,
                Id = foundTask.Id,
                DueDate = foundTask.DueDate,
                Completed = foundTask.Completed,
                ParentId = foundTask.ParentId,
                Priority = (TaskPriority)foundTask.Priority
            });
        }
コード例 #24
0
        public async Task <ProjectResponse> ExecuteAsync(ImportProjectRequest request, string owner)
        {
            var project = new Project {
                OwnerId     = Guid.Parse(owner),
                Title       = request.Title,
                Tasks       = new List <ProjectTask>(),
                Description = request.Description
            };

            foreach (var t in request.Items)
            {
                project.Tasks.Add(buildTree(t, project));
            }
            await _context.Projects.AddAsync(project);

            await _context.SaveChangesAsync();

            return(new ProjectResponse {
                Title = project.Title, Description = project.Description
            });
        }
コード例 #25
0
        public async Task <TodoViewModel> Create(string description)
        {
            TodoViewModel result;

            using (_context)
            {
                var todo = _context.Todos.Add(new Todo()
                {
                    Description = description
                });

                await _context.SaveChangesAsync();

                result = new TodoViewModel()
                {
                    ID = todo.Entity.ID, Description = todo.Entity.Description, Completed = todo.Entity.Completed
                };
            }

            return(result);
        }
コード例 #26
0
        public async Task <ProjectResponse> ExecuteAsync(UpdateProjectRequest request)
        {
            Project foundProject = await _context.Projects.FindAsync(request.Id);

            //TODO: check if user is owner of project before editing it
            //TODO: check if project not archived
            //TODO: add automapper
            if (foundProject != null)
            {
                foundProject.Title       = request.Title;
                foundProject.Description = request.Description;
                await _context.SaveChangesAsync();
            }
            return(foundProject == null
                ? null
                : new ProjectResponse
            {
                Title = foundProject.Title,
                Description = foundProject.Description,
                Id = foundProject.Id,
                Archived = foundProject.Archived
            });
        }
コード例 #27
0
        public async void Save(ThoughtDto thoughtDto)
        {
            using (context)
            {
                Thought thought;
                if (thoughtDto.ThoughtId > 0)
                {
                    thought = context.Thoughts
                              .SingleOrDefaultAsync(t => t.ThoughtId == thoughtDto.ThoughtId)
                              .Result;

                    thought.Update(
                        thoughtDto.Description,
                        (int)thoughtDto.Timeframe.TimeframeType,
                        thoughtDto.Timeframe.TimeframeDateTime,
                        thoughtDto.Project);

                    try
                    {
                        context.Update <Thought>(thought);
                        await context.SaveChangesAsync();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
                else
                {
                    thought = Thought.Create(thoughtDto.Description, thoughtDto.SortId, (int)thoughtDto.Timeframe.TimeframeType, thoughtDto.Timeframe.TimeframeDateTime, thoughtDto.Project);
                    context.Thoughts.Add(thought);
                    context.SaveChanges();
                }
            }
        }
コード例 #28
0
        public async virtual Task CreateAsync(TEntity entity)
        {
            await _dataset.AddAsync(entity);

            await _context.SaveChangesAsync();
        }
コード例 #29
0
 public Task <int> CommitAsync()
 {
     return(_context.SaveChangesAsync());
 }