public bool InsertNewTask(TaskNew taskNew)
        {
            using (var client = new SqlConnection(connectionString))
                using (var com = new SqlCommand())
                {
                    SqlTransaction transaction = client.BeginTransaction("Transaction");
                    com.Connection  = client;
                    com.CommandText = "INSERT INTO Task (IdTask, Name, Description, Deadline, IdTeam, IdAssignedTo, IdCreator) VALUES ((SELECT MAX(IdTask) FROM TASK) + 1, '@name', '@description', @deadline, @IdTeam, @IdAssignedTo, @IdCreator)";
                    com.Parameters.AddWithValue("name", taskNew.Name);
                    com.Parameters.AddWithValue("description", taskNew.Description);
                    com.Parameters.AddWithValue("deadline", taskNew.Deadline);
                    com.Parameters.AddWithValue("IdTeam", taskNew.IdTeam);
                    com.Parameters.AddWithValue("IdAssignedTo", taskNew.IdAssignedTo);
                    com.Parameters.AddWithValue("IdCreator", taskNew.IdCreator);

                    client.Open();
                    try
                    {
                        var nonq = com.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        transaction.Rollback();
                        return(false);
                    }

                    client.Close();
                }

            return(true);
        }
Beispiel #2
0
 public IActionResult InsertNewTask(TaskNew taskNew)
 {
     ;            if (!_dbService.InsertNewTask(taskNew))
     {
         return(BadRequest("Failed to insert"));
     }
     return(Ok(taskNew));
 }
Beispiel #3
0
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);
            var task = new TaskNew();

            //if (input.AssignedPersonId.HasValue)
            //{
            //    task.AssignedPersonId = input.AssignedPersonId.Value;
            //}
            _tasknewRepository.Insert(task);
        }