public ActionResult <Task> Create([FromBody] Task newTask) { try { return(Ok(_LS.Create(newTask))); } catch (System.Exception error) { return(BadRequest(error.Message)); } }
public ActionResult <Tasky> Create([FromBody] Tasky newTask) { try { return(Ok(_ts.Create(newTask))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <TasksController> > Create([FromBody] MyTask newTask) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newTask.CreatorId = userInfo.Id; MyTask created = _ts.Create(newTask); created.Creator = userInfo; return(Ok(created)); } catch (Exception err) { return(BadRequest(err.Message)); } }
public void UpsertShouldModifyTheGivenTask() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenTask)) .Options; using (var context = new TasksDbContext(options)) { var taskService = new TasksService(context); var added = taskService.Create(new TaskPostDTO { Title = "Booking1010", Description = "Verify booking commision", DateAdded = DateTime.Parse("2019-06-15T00:00:00"), Deadline = DateTime.Parse("2019-06-17T00:00:00"), TaskImportance = "High", TaskState = "Closed", DateClosed = null, Comments = new List <Comment>() { new Comment { Important = true, Text = "A nice task...", } }, }, null); context.Entry(added).State = EntityState.Detached; var update = new Task() { Title = "Updated", }; var updateResult = taskService.Upsert(added.Id, update); Assert.NotNull(updateResult); Assert.AreNotEqual(added.Title, updateResult.Title); Assert.AreEqual("Updated", updateResult.Title); } }
public async Task <ActionResult <string> > Create([FromBody] Task pm) { try { // This is the same as req.user.id string that is used to verify and attach to the next portion Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); _service.Create(pm, userInfo.Id); return(Ok("success")); } catch (NotAuthorized e) { return(Forbid(e.Message)); } catch (System.Exception e) { return(BadRequest(e.Message)); } }
public void GetByIdShouldReturnTaskWithCorrectId() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnTaskWithCorrectId)) .Options; using (var context = new TasksDbContext(options)) { var taskService = new TasksService(context); var added = new TaskPostDTO() { Title = "BookingNOW", Description = "Verify booking commision", DateAdded = DateTime.Parse("2019-06-15T00:00:00"), Deadline = DateTime.Parse("2019-06-17T00:00:00"), TaskImportance = "High", TaskState = "Closed", DateClosed = null, Comments = new List <Comment>() { new Comment { Important = true, Text = "A nice task...", } }, }; var current = taskService.Create(added, null); var expected = taskService.GetById(current.Id); Assert.IsNotNull(expected); Assert.AreEqual(expected.Title, current.Title); Assert.AreEqual(expected.Description, current.Description); Assert.AreEqual(expected.TaskImportance, current.TaskImportance); Assert.AreEqual(expected.TaskState, current.TaskState); Assert.AreEqual(expected.Id, current.Id); } }
public void DeleteTaskWithCommentsShouldDeleteTasksAndComments() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteTaskWithCommentsShouldDeleteTasksAndComments)) .Options; using (var context = new TasksDbContext(options)) { var tasksService = new TasksService(context); var expected = new TaskPostDTO() { Title = "Booking1010", Description = "Verify booking commision", DateAdded = DateTime.Parse("2019-06-15T00:00:00"), Deadline = DateTime.Parse("2019-06-17T00:00:00"), TaskImportance = "High", TaskState = "Closed", DateClosed = null, Comments = new List <Comment>() { new Comment { Important = true, Text = "A nice task...", } }, }; var actual = tasksService.Create(expected, null); var afterDelete = tasksService.Delete(actual.Id); int numberOfCommentsInDb = context.Comments.CountAsync().Result; var resultExpense = context.Tasks.Find(actual.Id); Assert.IsNotNull(afterDelete); Assert.IsNull(resultExpense); Assert.AreEqual(0, numberOfCommentsInDb); } }
public void GetAllShouldReturnCorrectNumberOfPagesForComments() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForComments)) .Options; using (var context = new TasksDbContext(options)) { var taskService = new TasksService(context); var commentService = new CommentsService(context); var added = new TaskPostDTO() { Title = "BookingNOW", Description = "Verify booking commision", DateAdded = DateTime.Parse("2019-06-15T00:00:00"), Deadline = DateTime.Parse("2019-06-17T00:00:00"), TaskImportance = "High", TaskState = "Closed", DateClosed = null, Comments = new List <Comment>() { new Comment { Important = true, Text = "A nice task...", Owner = null } }, }; var current = taskService.Create(added, null); var allComments = commentService.GetAll(string.Empty, 1); Assert.AreEqual(1, allComments.NumberOfPages); } }
public void GetAllShouldReturnCorrectNumberOfPagesForTasks() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForTasks)) .Options; using (var context = new TasksDbContext(options)) { var taskService = new TasksService(context); var added = taskService.Create(new LabIV.DTO.TaskPostDTO { Title = "Booking Commision", Description = "Verify booking commision", DateAdded = DateTime.Parse("2019-06-15T00:00:00"), Deadline = DateTime.Parse("2019-06-17T00:00:00"), TaskImportance = "High", TaskState = "Closed", DateClosed = null, Comments = new List <Comment>() { new Comment { Important = true, Text = "A nice task...", } }, }, null); DateTime from = DateTime.Parse("2019-06-13T00:00:00"); DateTime to = DateTime.Parse("2019-06-19T00:00:00"); var allTasks = taskService.GetAll(1, from, to); Assert.AreEqual(1, allTasks.Entries.Count); Assert.IsNotNull(allTasks); } }
public void CreateShouldAddAndReturnTheCreatedTask() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(CreateShouldAddAndReturnTheCreatedTask)) .Options; using (var context = new TasksDbContext(options)) { var taskService = new TasksService(context); var added = taskService.Create(new LabIV.DTO.TaskPostDTO { Title = "Booking1010", Description = "Verify booking commision", DateAdded = DateTime.Parse("2019-06-15T00:00:00"), Deadline = DateTime.Parse("2019-06-17T00:00:00"), TaskImportance = "High", TaskState = "Closed", DateClosed = null, Comments = new List <Comment>() { new Comment { Important = true, Text = "A nice task...", } }, }, null); Assert.IsNotNull(added); Assert.AreEqual("Booking1010", added.Title); Assert.AreNotEqual("BookingNOW", added.Title); } }
public ActionResult <Task> Create(Task task) { _tasksService.Create(task); return(CreatedAtRoute("GetTask", new { id = task.Id.ToString() }, task)); }