/// <summary> /// Создает комментарий. /// </summary> /// <param name="comment">Комментарий.</param> /// <returns>Идентификаторо созданного комментария.</returns> public int Create(CommentItem comment) { if (string.IsNullOrEmpty(comment.Text)) { throw new Exception("Поле 'Text' не должно быть пустым."); } return _commentRepository.Create(comment); }
/// <summary> /// Создает новый комментарий. /// </summary> /// <param name="comment">Комментарий.</param> /// <returns>Идентификатор созданного комментария.</returns> public int Create(CommentItem comment) { using (var sqlh = new SqlHelper()) { return sqlh.ExecScalar<int>(@" insert into Task.comment ( add_date, person, text, task ) values ( @AddDate, @PersonId, @Text, @TaskId ) select scope_identity()", comment); } }
/// <summary> /// Проверяет еквивалентны ли два комментария. /// </summary> /// Описание входных параметров. /// <param name="first_comment">Первый комментарий для сравнения.</param> /// <param name="second_comment">Второй комментарий для сравнения.</param> private void AreEqualComments(CommentItem first_comment, CommentItem second_comment) { Assert.AreEqual(first_comment.Id, second_comment.Id); Assert.AreEqual(first_comment.AddDate, second_comment.AddDate); Assert.AreEqual(first_comment.PersonId, second_comment.PersonId); Assert.AreEqual(first_comment.Text, second_comment.Text); Assert.AreEqual(first_comment.TaskId, second_comment.TaskId); }
public void SetUp() { _transactionScope = new TransactionScope(); _commentRepository = new CommentRepository(); _personRepository = new PersonRepository(); _taskRepository = new TaskRepository(); first_person = new PersonItem() { LastName = "Никонов", FirstName = "Денис", Birthday = DateTime.Now.Date, FatherName = "Олегович" }; second_person = new PersonItem() { LastName = "Кажин", FirstName = "Филипп", Birthday = DateTime.Now.AddMonths(-3).Date, FatherName = "Александрович" }; first_task = new TaskItem() { Author = "1", Deadline = DateTime.Now.AddDays(7).Date, Created = DateTime.Now.Date, Performer = "1", Header = "Тестирование демонстрационной задачи", IsOpen = true, IsPerform = false, Mem = "Описание", Number = 1, Priority = 0, Prefix = TaskPrefix.Refactoring }; second_task = new TaskItem() { Author = "2", Deadline = DateTime.Now.AddDays(8).Date, Created = DateTime.Now.Date, Performer = "2", Header = "Тестирование демонстрационной задачи 2", IsOpen = false, IsPerform = true, Mem = "Описание2", Number = 2, Priority = 5, Prefix = TaskPrefix.Demo }; _comment = new CommentItem() { AddDate = DateTime.Now.Date, PersonId = _personRepository.Create(first_person), Text = "Задача номер 1", TaskId = _taskRepository.Create(first_task) }; _commentNew = new CommentItem() { AddDate = DateTime.Now.AddYears(-1).Date, PersonId = _personRepository.Create(second_person), Text = "Задача номер 2", TaskId = _taskRepository.Create(second_task) }; }
/// <summary> /// Обновляет данные по комментарию. /// </summary> /// <param name="comment">Комментарий.</param> public void Update(CommentItem comment) { using (var sqlh = new SqlHelper()) { sqlh.ExecNoQuery(@" update Task.comment set add_date = @AddDate, person = @PersonId, text = @Text, task = @TaskId where comment = @Id", comment); } }
public JsonResult SendMessage(CommentItem comment) { var id = _commentService.Create(comment); return Json(new { success = true, id, is_deleter = Access.CheckRole("Comment.Deleter") }, JsonRequestBehavior.AllowGet); }
public void SetUp() { _commentRepository = Mock.Of<ICommentRepository>(); _commentService = new CommentService(_commentRepository); _comment = new CommentItem() { Id = 1, AddDate = DateTime.Now.AddYears(-1).Date, PersonId = 1, Text = "Тестовая задача номер 1", TaskId = 2 }; }
/// <summary> /// Изменяет данные о комментарие. /// </summary> /// <param name="comment">Комментарий.</param> public void Update(CommentItem comment) { if (string.IsNullOrEmpty(comment.Text)) { throw new Exception("Поле 'Text' не должно быть пустым."); } if (GetById(comment.Id) == null) { throw new Exception("Комментарий не найден."); } _commentRepository.Update(comment); }