public IHttpActionResult Get()
 {
     try
     {
         using (var context = new KanbanDBModel())
         {
             var projectQuery = context.Database.SqlQuery <Project>("dbo.GetProjects");
             return(Ok(projectQuery.ToArray()));
         }
     }catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
示例#2
0
 public IHttpActionResult GetAllStatuses()
 {
     try
     {
         using (var context = new KanbanDBModel())
         {
             var taskStatusQuery = context.Database.SqlQuery <TaskStatus>("dbo.GetTaskStatuses");
             return(Ok(taskStatusQuery.ToArray()));
         }
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
        public IHttpActionResult Post([FromUri] long projectId, [FromBody] TaskCreateRequest taskObj)
        {
            TaskCreateResponse result = new TaskCreateResponse();

            using (var context = new KanbanDBModel())
            {
                var cmd = context.Database.Connection.CreateCommand();
                cmd.CommandText = "[dbo].[InsertTask]";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;


                cmd.Parameters.Add(new SqlParameter("ProjectId", projectId));
                cmd.Parameters.Add(new SqlParameter("TaskName", taskObj.TaskName));
                cmd.Parameters.Add(new SqlParameter("TaskDescription", taskObj.TaskDescription));
                cmd.Parameters.Add(new SqlParameter("TaskStatus", taskObj.TaskStatus));

                try
                {
                    context.Database.Connection.Open();
                    var reader = cmd.ExecuteReader();

                    var operationStatusQuery = ((IObjectContextAdapter)context)
                                               .ObjectContext
                                               .Translate <OperationStatusInfo>(reader);

                    result.Result = operationStatusQuery.FirstOrDefault();

                    reader.NextResult();

                    var taskQuery = ((IObjectContextAdapter)context)
                                    .ObjectContext
                                    .Translate <TaskInfo>(reader);

                    result.Task = taskQuery.FirstOrDefault();

                    return(Ok(result));
                }
                catch (Exception ex)
                {
                    return(InternalServerError(ex));
                }
                finally
                {
                    context.Database.Connection.Close();
                }
            }
        }
示例#4
0
 public IHttpActionResult Put([FromUri] long taskId, [FromBody] TaskStatusUpdateInfo taskStatusObject)
 {
     try
     {
         using (var context = new KanbanDBModel())
         {
             SqlParameter[] parameters = new SqlParameter[2];
             parameters[0] = new SqlParameter("TaskId", taskId);
             parameters[1] = new SqlParameter("Status", taskStatusObject.Status);
             var operationQuery = context.Database.SqlQuery <OperationStatusInfo>("dbo.UpdateTaskStatus @TaskId , @Status", parameters);
             return(Ok(operationQuery.FirstOrDefault()));
         }
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
        public IHttpActionResult GetTasksByProjectId([FromUri] long projectId)
        {
            ProjectTaskInfo result = new ProjectTaskInfo();

            using (var context = new KanbanDBModel())
            {
                var cmd = context.Database.Connection.CreateCommand();
                cmd.CommandText = "[dbo].[GetTasksByProjectId]";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("ProjectId", projectId));

                try
                {
                    context.Database.Connection.Open();
                    var reader = cmd.ExecuteReader();

                    var projectQuery = ((IObjectContextAdapter)context)
                                       .ObjectContext
                                       .Translate <Project>(reader);

                    result.Project = projectQuery.FirstOrDefault();

                    reader.NextResult();

                    var taskQuery = ((IObjectContextAdapter)context)
                                    .ObjectContext
                                    .Translate <TaskInfo>(reader);

                    result.Tasks = taskQuery.ToArray();

                    return(Ok(result));
                }catch (Exception ex)
                {
                    return(InternalServerError(ex));
                }
                finally
                {
                    context.Database.Connection.Close();
                }
            }
        }